X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e90c1d2a19361551eb07778280f22be3e759cf64..f22e0c3c3f90510f1a92ab148f20b2453e338626:/src/common/socket.cpp diff --git a/src/common/socket.cpp b/src/common/socket.cpp index f66313eaf1..6ee284089e 100644 --- a/src/common/socket.cpp +++ b/src/common/socket.cpp @@ -33,6 +33,7 @@ #include "wx/utils.h" #include "wx/module.h" #include "wx/log.h" +#include "wx/intl.h" #include <stdlib.h> #include <string.h> @@ -45,30 +46,28 @@ #include "wx/socket.h" -#if defined(__WXMSW__) -#define PROCESS_EVENTS() wxYield() +#if defined(__WXMSW__) || defined(__WXPM__) || defined(__WXMOTIF__) || defined(__WXMAC__) + #define PROCESS_EVENTS() wxYield() #elif defined(__WXGTK__) -#include <gtk/gtk.h> -#define PROCESS_EVENTS() gtk_main_iteration() -#endif + #include <gtk/gtk.h> + #define PROCESS_EVENTS() gtk_main_iteration() +#endif // -------------------------------------------------------------- // ClassInfos // -------------------------------------------------------------- -#if !USE_SHARED_LIBRARY IMPLEMENT_CLASS(wxSocketBase, wxObject) IMPLEMENT_CLASS(wxSocketServer, wxSocketBase) IMPLEMENT_CLASS(wxSocketClient, wxSocketBase) IMPLEMENT_DYNAMIC_CLASS(wxSocketEvent, wxEvent) -#endif class wxSocketState : public wxObject { public: bool notify_state; GSocketEventFlags evt_notify_state; - wxSocketBase::wxSockFlags socket_flags; + wxSockFlags socket_flags; wxSocketBase::wxSockCbk c_callback; char *c_callback_data; @@ -80,8 +79,7 @@ public: // wxSocketBase ctor and dtor // -------------------------------------------------------------- -wxSocketBase::wxSocketBase(wxSocketBase::wxSockFlags _flags, - wxSocketBase::wxSockType _type) : +wxSocketBase::wxSocketBase(wxSockFlags _flags, wxSockType _type) : wxEvtHandler(), m_socket(NULL), m_id(-1), m_flags(_flags), m_type(_type), @@ -188,7 +186,7 @@ wxUint32 wxSocketBase::DeferRead(char *buffer, wxUint32 nbytes) DoDefer(); } - // Wait for buffer completion. + // Wait for buffer completion. while (m_defer_buffer != NULL) PROCESS_EVENTS(); @@ -235,13 +233,13 @@ wxUint32 wxSocketBase::_Read(char* buffer, wxUint32 nbytes) // If the socket is not connected, or we have got the whole // needed buffer, return immedately - if (!m_connected || !m_socket || !nbytes) + if (!m_connected || !m_socket || !nbytes) return total; // Possible combinations (they are checked in this order) // NOWAIT // SPEED | WAITALL - // SPEED + // SPEED // WAITALL // NONE // @@ -316,7 +314,7 @@ wxSocketBase& wxSocketBase::ReadMsg(char* buffer, wxUint32 nbytes) if (sig != 0xfeeddead) { - wxLogMessage(T("Warning: invalid signature returned to ReadMsg")); + wxLogWarning( _("TCP: invalid signature returned to ReadMsg.")); goto exit; } @@ -374,7 +372,7 @@ wxSocketBase& wxSocketBase::ReadMsg(char* buffer, wxUint32 nbytes) if (sig != 0xdeadfeed) { - //wxLogMessage(T("Warning: invalid signature returned to ReadMsg")); + //wxLogMessage(wxT("Warning: invalid signature returned to ReadMsg")); goto exit; } @@ -442,7 +440,7 @@ wxUint32 wxSocketBase::DeferWrite(const char *buffer, wxUint32 nbytes) DoDefer(); } - // Wait for buffer completion. + // Wait for buffer completion. while (m_defer_buffer != NULL) PROCESS_EVENTS(); @@ -452,8 +450,8 @@ wxUint32 wxSocketBase::DeferWrite(const char *buffer, wxUint32 nbytes) m_defer_timer = NULL; m_defering = NO_DEFER; - wxString s; - s.Printf("Saliendo de DeferWrite: total %d bytes", nbytes-m_defer_nbytes); + //wxString s; + //s.Printf(wxT("Saliendo de DeferWrite: total %d bytes"), nbytes-m_defer_nbytes); //wxLogMessage(s); return nbytes-m_defer_nbytes; @@ -490,7 +488,7 @@ wxUint32 wxSocketBase::_Write(const char *buffer, wxUint32 nbytes) // Possible combinations (they are checked in this order) // NOWAIT // SPEED | WAITALL - // SPEED + // SPEED // WAITALL // NONE // @@ -686,7 +684,7 @@ wxSocketBase& wxSocketBase::Discard() // TODO: TriggerRead return *this; - + #undef MAX_BUFSIZE } @@ -890,7 +888,7 @@ void wxSocketBase::SetTimeout(long seconds) m_timeout = seconds; if (m_socket) - GSocket_SetTimeout(m_socket, m_timeout); + GSocket_SetTimeout(m_socket, m_timeout * 1000); } // -------------------------------------------------------------- @@ -901,7 +899,7 @@ void wxSocketBase::SetFlags(wxSockFlags _flags) { m_flags = _flags; } - + // -------------------------------------------------------------- // wxSocketBase callback management // -------------------------------------------------------------- @@ -1106,7 +1104,7 @@ wxSocketServer::wxSocketServer(wxSockAddress& addr_man, return; } - GSocket_SetTimeout(m_socket, m_timeout); + GSocket_SetTimeout(m_socket, m_timeout * 1000); GSocket_SetCallback(m_socket, GSOCK_INPUT_FLAG | GSOCK_OUTPUT_FLAG | GSOCK_LOST_FLAG | GSOCK_CONNECTION_FLAG, wx_socket_callback, (char *)this); @@ -1144,7 +1142,7 @@ bool wxSocketServer::AcceptWith(wxSocketBase& sock, bool wait) sock.m_socket = child_socket; sock.m_connected = TRUE; - GSocket_SetTimeout(sock.m_socket, sock.m_timeout); + GSocket_SetTimeout(sock.m_socket, sock.m_timeout * 1000); GSocket_SetCallback(sock.m_socket, GSOCK_INPUT_FLAG | GSOCK_OUTPUT_FLAG | GSOCK_LOST_FLAG | GSOCK_CONNECTION_FLAG, wx_socket_callback, (char *)&sock); @@ -1208,7 +1206,7 @@ bool wxSocketClient::Connect(wxSockAddress& addr_man, bool wait) if (!m_socket) return FALSE; - GSocket_SetTimeout(m_socket, m_timeout); + GSocket_SetTimeout(m_socket, m_timeout * 1000); GSocket_SetCallback(m_socket, GSOCK_INPUT_FLAG | GSOCK_OUTPUT_FLAG | GSOCK_LOST_FLAG | GSOCK_CONNECTION_FLAG, wx_socket_callback, (char *)this);