#include <wx/string.h>
#include <wx/timer.h>
#include <wx/utils.h>
+#include <wx/module.h>
#include <wx/log.h>
#include <stdlib.h>
/////////////////////////////////////////////////////////////////////////////
// wxSocket headers
/////////////////////////////////////////////////////////////////////////////
-#include <wx/module.h>
#include <wx/sckaddr.h>
#include <wx/socket.h>
}
};
-int wxSocketBase::DeferRead(char *buffer, size_t nbytes)
+int wxSocketBase::DeferRead(char *buffer, wxUint32 nbytes)
{
wxSocketEventFlags old_event_flags;
bool old_notify_state;
return nbytes-m_defer_nbytes;
}
-wxSocketBase& wxSocketBase::Read(char* buffer, size_t nbytes)
+wxSocketBase& wxSocketBase::Read(char* buffer, wxUint32 nbytes)
{
int ret = 1;
return *this;
}
-wxSocketBase& wxSocketBase::ReadMsg(char* buffer, size_t nbytes)
+wxSocketBase& wxSocketBase::ReadMsg(char* buffer, wxUint32 nbytes)
{
unsigned long len, len2, sig;
struct {
} msg;
// sig should be an explicit 32-bit unsigned integer; I've seen
- // compilers in which size_t was actually a 16-bit unsigned integer
+ // compilers in which wxUint32 was actually a 16-bit unsigned integer
Read((char *)&msg, sizeof(msg));
if (m_lcount != sizeof(msg))
return *this;
sig = msg.sig[0] & 0xff;
- sig |= (size_t)(msg.sig[1] & 0xff) << 8;
- sig |= (size_t)(msg.sig[2] & 0xff) << 16;
- sig |= (size_t)(msg.sig[3] & 0xff) << 24;
+ sig |= (wxUint32)(msg.sig[1] & 0xff) << 8;
+ sig |= (wxUint32)(msg.sig[2] & 0xff) << 16;
+ sig |= (wxUint32)(msg.sig[3] & 0xff) << 24;
if (sig != 0xfeeddead)
return *this;
len = msg.len[0] & 0xff;
- len |= (size_t)(msg.len[1] & 0xff) << 8;
- len |= (size_t)(msg.len[2] & 0xff) << 16;
- len |= (size_t)(msg.len[3] & 0xff) << 24;
+ len |= (wxUint32)(msg.len[1] & 0xff) << 8;
+ len |= (wxUint32)(msg.len[2] & 0xff) << 16;
+ len |= (wxUint32)(msg.len[3] & 0xff) << 24;
// len2 is incorrectly computed in the original; this sequence is
// the fix
return *this;
sig = msg.sig[0] & 0xff;
- sig |= (size_t)(msg.sig[1] & 0xff) << 8;
- sig |= (size_t)(msg.sig[2] & 0xff) << 16;
- sig |= (size_t)(msg.sig[3] & 0xff) << 24;
+ sig |= (wxUint32)(msg.sig[1] & 0xff) << 8;
+ sig |= (wxUint32)(msg.sig[2] & 0xff) << 16;
+ sig |= (wxUint32)(msg.sig[3] & 0xff) << 24;
// ERROR
if (sig != 0xdeadfeed)
return *this;
}
-wxSocketBase& wxSocketBase::Peek(char* buffer, size_t nbytes)
+wxSocketBase& wxSocketBase::Peek(char* buffer, wxUint32 nbytes)
{
Read(buffer, nbytes);
CreatePushbackAfter(buffer, nbytes);
return *this;
}
-int wxSocketBase::DeferWrite(const char *buffer, size_t nbytes)
+int wxSocketBase::DeferWrite(const char *buffer, wxUint32 nbytes)
{
wxSocketEventFlags old_event_flags;
bool old_notify_state;
return nbytes-m_defer_nbytes;
}
-wxSocketBase& wxSocketBase::Write(const char *buffer, size_t nbytes)
+wxSocketBase& wxSocketBase::Write(const char *buffer, wxUint32 nbytes)
{
int ret;
return *this;
}
-wxSocketBase& wxSocketBase::WriteMsg(const char *buffer, size_t nbytes)
+wxSocketBase& wxSocketBase::WriteMsg(const char *buffer, wxUint32 nbytes)
{
struct {
char sig[4];
msg.sig[2] = (char) 0xed;
msg.sig[3] = (char) 0xfe;
- msg.len[0] = (char) nbytes & 0xff;
+ msg.len[0] = (char) nbytes & 0xff;
msg.len[1] = (char) (nbytes >> 8) & 0xff;
msg.len[2] = (char) (nbytes >> 16) & 0xff;
msg.len[3] = (char) (nbytes >> 24) & 0xff;
#endif // __VISUALC__
}
-wxSocketBase& wxSocketBase::Unread(const char *buffer, size_t nbytes)
+wxSocketBase& wxSocketBase::Unread(const char *buffer, wxUint32 nbytes)
{
m_lcount = 0;
if (nbytes != 0) {
{
#define MAX_BUFSIZE (10*1024)
char *my_data = new char[MAX_BUFSIZE];
- size_t recv_size = MAX_BUFSIZE;
+ wxUint32 recv_size = MAX_BUFSIZE;
SaveState();
SetFlags(NOWAIT | SPEED);
// --------- wxSocketBase pushback library ----------------------
// --------------------------------------------------------------
-void wxSocketBase::CreatePushbackAfter(const char *buffer, size_t size)
+void wxSocketBase::CreatePushbackAfter(const char *buffer, wxUint32 size)
{
char *curr_pos;
m_unrd_size += size;
}
-void wxSocketBase::CreatePushbackBefore(const char *buffer, size_t size)
+void wxSocketBase::CreatePushbackBefore(const char *buffer, wxUint32 size)
{
if (m_unread == NULL)
m_unread = (char *)malloc(size);
memcpy(m_unread, buffer, size);
}
-size_t wxSocketBase::GetPushback(char *buffer, size_t size, bool peek)
+wxUint32 wxSocketBase::GetPushback(char *buffer, wxUint32 size, bool peek)
{
if (!m_unrd_size)
return 0;
// --------------------------------------------------------------
// --------- wxSocketClient Connect functions -------------------
// --------------------------------------------------------------
-bool wxSocketClient::Connect(wxSockAddress& addr_man, bool WXUNUSED(wait) )
+bool wxSocketClient::Connect(wxSockAddress& addr_man, bool wait)
{
+ GSocketError err;
+
if (IsConnected())
Close();
m_connected = FALSE;
+ // GRG: If wait == FALSE, then set the socket to
+ // nonblocking. I will set it back to blocking later,
+ // but I am not sure if this is really a good idea.
+ // IMO, all GSockets objects used in wxSocket should
+ // be non-blocking.
+ // --------------------------------
+ if (!wait)
+ GSocket_SetNonBlocking(m_socket, TRUE);
+
// Update the flags of m_socket.
SetFlags(m_flags);
+
+ // Try to connect
GSocket_SetPeer(m_socket, addr_man.GetAddress());
- if (GSocket_Connect(m_socket, GSOCK_STREAMED) != GSOCK_NOERROR)
+ err = GSocket_Connect(m_socket, GSOCK_STREAMED);
+
+ if (!wait)
+ GSocket_SetNonBlocking(m_socket, FALSE);
+
+ if (err != GSOCK_NOERROR)
return FALSE;
// Enables bg events.