added SetInitialSocketBuffers() to allow changing the send/receive buffer sizes (patch 1829576)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50028 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2007-11-17 15:21:26 +00:00
parent 795b0f1444
commit 8c029a5b02
6 changed files with 50 additions and 2 deletions

View File

@@ -80,6 +80,13 @@ public:
void *optval, int *optlen); void *optval, int *optlen);
GSocketError SetSockOpt(int level, int optname, GSocketError SetSockOpt(int level, int optname,
const void *optval, int optlen); const void *optval, int optlen);
void SetInitialSocketBuffers(int recv, int send)
{
m_initialRecvBufferSize = recv;
m_initialSendBufferSize = send;
}
protected: protected:
GSocketError Input_Timeout(); GSocketError Input_Timeout();
GSocketError Output_Timeout(); GSocketError Output_Timeout();
@@ -89,6 +96,8 @@ protected:
int Send_Stream(const char *buffer, int size); int Send_Stream(const char *buffer, int size);
int Send_Dgram(const char *buffer, int size); int Send_Dgram(const char *buffer, int size);
bool m_ok; bool m_ok;
int m_initialRecvBufferSize;
int m_initialSendBufferSize;
/* TODO: Make these protected */ /* TODO: Make these protected */
public: public:

View File

@@ -263,8 +263,21 @@ public:
bool WaitOnConnect(long seconds = -1, long milliseconds = 0); bool WaitOnConnect(long seconds = -1, long milliseconds = 0);
// Sets initial socket buffer sizes using the SO_SNDBUF and SO_RCVBUF options
// before calling connect (either one can be -1 to leave it unchanged)
void SetInitialSocketBuffers(int recv, int send)
{
m_initialRecvBufferSize = recv;
m_initialSendBufferSize = send;
}
private: private:
virtual bool DoConnect(wxSockAddress& addr, wxSockAddress* local, bool wait = true); virtual bool
DoConnect(wxSockAddress& addr, wxSockAddress* local, bool wait = true);
// buffer sizes, -1 if unset and defaults should be used
int m_initialRecvBufferSize;
int m_initialSendBufferSize;
DECLARE_NO_COPY_CLASS(wxSocketClient) DECLARE_NO_COPY_CLASS(wxSocketClient)
}; };

View File

@@ -72,6 +72,12 @@ public:
const void *optval, int optlen); const void *optval, int optlen);
virtual void Detected_Read(); virtual void Detected_Read();
virtual void Detected_Write(); virtual void Detected_Write();
void SetInitialSocketBuffers(int recv, int send)
{
m_initialRecvBufferSize = recv;
m_initialSendBufferSize = send;
}
protected: protected:
void Enable(GSocketEvent event); void Enable(GSocketEvent event);
void Disable(GSocketEvent event); void Disable(GSocketEvent event);
@@ -82,6 +88,8 @@ protected:
int Send_Stream(const char *buffer, int size); int Send_Stream(const char *buffer, int size);
int Send_Dgram(const char *buffer, int size); int Send_Dgram(const char *buffer, int size);
bool m_ok; bool m_ok;
int m_initialRecvBufferSize;
int m_initialSendBufferSize;
public: public:
/* DFE: We can't protect these data member until the GUI code is updated */ /* DFE: We can't protect these data member until the GUI code is updated */
/* protected: */ /* protected: */

View File

@@ -1303,6 +1303,10 @@ bool wxSocketClient::DoConnect(wxSockAddress& addr_man, wxSockAddress* local, bo
m_socket->SetLocal(la); m_socket->SetLocal(la);
} }
#if defined(__WXMSW__) || defined(__WXGTK__)
m_socket->SetInitialSocketBuffers(m_initialRecvBufferSize, m_initialSendBufferSize);
#endif
m_socket->SetPeer(addr_man.GetAddress()); m_socket->SetPeer(addr_man.GetAddress());
err = m_socket->Connect(GSOCK_STREAMED); err = m_socket->Connect(GSOCK_STREAMED);

View File

@@ -179,7 +179,9 @@ GSocket::GSocket()
m_reusable = false; m_reusable = false;
m_broadcast = false; m_broadcast = false;
m_dobind = true; m_dobind = true;
m_initialRecvBufferSize = -1;
m_initialSendBufferSize = -1;
assert(gs_gui_functions); assert(gs_gui_functions);
/* Per-socket GUI-specific initialization */ /* Per-socket GUI-specific initialization */
m_ok = gs_gui_functions->Init_Socket(this); m_ok = gs_gui_functions->Init_Socket(this);
@@ -630,6 +632,11 @@ GSocketError GSocket::Connect(GSocketStream stream)
setsockopt(m_fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&arg, sizeof(arg)); setsockopt(m_fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&arg, sizeof(arg));
} }
if (m_initialRecvBufferSize >= 0)
setsockopt(m_fd, SOL_SOCKET, SO_RCVBUF, (const char*)&m_initialRecvBufferSize, sizeof(m_initialRecvBufferSize));
if (m_initialSendBufferSize >= 0)
setsockopt(m_fd, SOL_SOCKET, SO_SNDBUF, (const char*)&m_initialSendBufferSize, sizeof(m_initialSendBufferSize));
// If a local address has been set, then we need to bind to it before calling connect // If a local address has been set, then we need to bind to it before calling connect
if (m_local && m_local->m_addr) if (m_local && m_local->m_addr)
{ {

View File

@@ -541,6 +541,8 @@ GSocket::GSocket()
m_timeout = 10*60*1000; m_timeout = 10*60*1000;
/* 10 minutes * 60 sec * 1000 millisec */ /* 10 minutes * 60 sec * 1000 millisec */
m_establishing = false; m_establishing = false;
m_initialRecvBufferSize = -1;
m_initialSendBufferSize = -1;
assert(gs_gui_functions); assert(gs_gui_functions);
/* Per-socket GUI-specific initialization */ /* Per-socket GUI-specific initialization */
@@ -1019,6 +1021,11 @@ GSocketError GSocket::Connect(GSocketStream stream)
#endif #endif
} }
if (m_initialRecvBufferSize >= 0)
setsockopt(m_fd, SOL_SOCKET, SO_RCVBUF, (const char*)&m_initialRecvBufferSize, sizeof(m_initialRecvBufferSize));
if (m_initialSendBufferSize >= 0)
setsockopt(m_fd, SOL_SOCKET, SO_SNDBUF, (const char*)&m_initialSendBufferSize, sizeof(m_initialSendBufferSize));
// If a local address has been set, then we need to bind to it before calling connect // If a local address has been set, then we need to bind to it before calling connect
if (m_local && m_local->m_addr) if (m_local && m_local->m_addr)
{ {