Added #include to get FIONBIO on Solaris 2.6
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@727 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
// RCS_ID: $Id$
|
// RCS_ID: $Id$
|
||||||
// License: see wxWindows license
|
// License: see wxWindows license
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
#ifdef __GNUG__
|
#ifdef __GNUG__
|
||||||
#pragma implementation "socket.h"
|
#pragma implementation "socket.h"
|
||||||
// #pragma interface
|
// #pragma interface
|
||||||
// #pragma implementation "socket.cpp"
|
// #pragma implementation "socket.cpp"
|
||||||
@@ -54,6 +54,10 @@
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#ifdef sun
|
||||||
|
#include <sys/filio.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // __UNIX__
|
#endif // __UNIX__
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
@@ -183,7 +187,7 @@ public:
|
|||||||
wxSockWakeUp *auto_wakeup;
|
wxSockWakeUp *auto_wakeup;
|
||||||
wxSocketBase::wxRequestNotify type;
|
wxSocketBase::wxRequestNotify type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Some internal define
|
// Some internal define
|
||||||
@@ -269,7 +273,7 @@ bool wxSocketBase::Close()
|
|||||||
while (node) {
|
while (node) {
|
||||||
SockRequest *req = (SockRequest *)node->Data();
|
SockRequest *req = (SockRequest *)node->Data();
|
||||||
req->done = TRUE;
|
req->done = TRUE;
|
||||||
|
|
||||||
n = node->Next();
|
n = node->Next();
|
||||||
delete node;
|
delete node;
|
||||||
node = n;
|
node = n;
|
||||||
@@ -328,7 +332,7 @@ wxSocketBase& wxSocketBase::ReadMsg(char* buffer, size_t nbytes)
|
|||||||
{
|
{
|
||||||
SockMsg msg;
|
SockMsg msg;
|
||||||
size_t len, len2, sig;
|
size_t len, len2, sig;
|
||||||
|
|
||||||
Read((char *)&msg, sizeof(msg));
|
Read((char *)&msg, sizeof(msg));
|
||||||
if (m_lcount != sizeof(msg))
|
if (m_lcount != sizeof(msg))
|
||||||
return *this;
|
return *this;
|
||||||
@@ -371,7 +375,7 @@ wxSocketBase& wxSocketBase::ReadMsg(char* buffer, size_t nbytes)
|
|||||||
wxSocketBase& wxSocketBase::WriteMsg(const char *buffer, size_t nbytes)
|
wxSocketBase& wxSocketBase::WriteMsg(const char *buffer, size_t nbytes)
|
||||||
{
|
{
|
||||||
SockMsg msg;
|
SockMsg msg;
|
||||||
|
|
||||||
msg.sig[0] = (char) 0xad;
|
msg.sig[0] = (char) 0xad;
|
||||||
msg.sig[1] = (char) 0xde;
|
msg.sig[1] = (char) 0xde;
|
||||||
msg.sig[2] = (char) 0xed;
|
msg.sig[2] = (char) 0xed;
|
||||||
@@ -385,7 +389,7 @@ wxSocketBase& wxSocketBase::WriteMsg(const char *buffer, size_t nbytes)
|
|||||||
if (Write((char *)&msg, sizeof(msg)).LastCount() < sizeof(msg))
|
if (Write((char *)&msg, sizeof(msg)).LastCount() < sizeof(msg))
|
||||||
return *this;
|
return *this;
|
||||||
if (Write(buffer, nbytes).LastCount() < nbytes)
|
if (Write(buffer, nbytes).LastCount() < nbytes)
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
msg.sig[0] = (char) 0xed;
|
msg.sig[0] = (char) 0xed;
|
||||||
msg.sig[1] = (char) 0xfe;
|
msg.sig[1] = (char) 0xfe;
|
||||||
@@ -432,7 +436,7 @@ void wxSocketBase::Discard()
|
|||||||
|
|
||||||
SaveState();
|
SaveState();
|
||||||
SetFlags((wxSockFlags)(NOWAIT | SPEED));
|
SetFlags((wxSockFlags)(NOWAIT | SPEED));
|
||||||
|
|
||||||
while (recv_size == MAX_BUFSIZE) {
|
while (recv_size == MAX_BUFSIZE) {
|
||||||
recv_size = Read(my_data, MAX_BUFSIZE).LastCount();
|
recv_size = Read(my_data, MAX_BUFSIZE).LastCount();
|
||||||
}
|
}
|
||||||
@@ -459,7 +463,7 @@ bool wxSocketBase::GetPeer(wxSockAddress& addr_man) const
|
|||||||
#else
|
#else
|
||||||
if (getpeername(m_fd, (struct sockaddr *)&my_addr, (unsigned int *)&len_addr) < 0)
|
if (getpeername(m_fd, (struct sockaddr *)&my_addr, (unsigned int *)&len_addr) < 0)
|
||||||
#endif
|
#endif
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
addr_man.Disassemble(&my_addr, len_addr);
|
addr_man.Disassemble(&my_addr, len_addr);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@@ -510,7 +514,7 @@ void wxSocketBase::RestoreState()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
wxSockState *state = (wxSockState *)node->Data();
|
wxSockState *state = (wxSockState *)node->Data();
|
||||||
|
|
||||||
SetFlags(state->flags);
|
SetFlags(state->flags);
|
||||||
m_neededreq = state->cbk_set;
|
m_neededreq = state->cbk_set;
|
||||||
m_cbk = state->cbk;
|
m_cbk = state->cbk;
|
||||||
@@ -542,7 +546,7 @@ bool wxSocketBase::_Wait(long seconds, long microseconds, int type)
|
|||||||
|
|
||||||
if (seconds != -1)
|
if (seconds != -1)
|
||||||
wakeup.Start((int)(seconds*1000 + (microseconds / 1000)), TRUE);
|
wakeup.Start((int)(seconds*1000 + (microseconds / 1000)), TRUE);
|
||||||
|
|
||||||
m_waitflags = 0x80 | type;
|
m_waitflags = 0x80 | type;
|
||||||
while (m_waitflags & 0x80)
|
while (m_waitflags & 0x80)
|
||||||
PROCESS_EVENTS();
|
PROCESS_EVENTS();
|
||||||
@@ -1054,7 +1058,7 @@ void wxSocketBase::WantBuffer(char *buffer, size_t nbytes,
|
|||||||
|
|
||||||
SockRequest *buf = new SockRequest;
|
SockRequest *buf = new SockRequest;
|
||||||
wxSockWakeUp s_wake(NULL, (int *)&buf_timed_out, (int)TRUE);
|
wxSockWakeUp s_wake(NULL, (int *)&buf_timed_out, (int)TRUE);
|
||||||
|
|
||||||
m_wantbuf++;
|
m_wantbuf++;
|
||||||
req_list[evt].Append(buf);
|
req_list[evt].Append(buf);
|
||||||
|
|
||||||
@@ -1103,17 +1107,17 @@ wxSocketServer::wxSocketServer(wxSockAddress& addr_man,
|
|||||||
|
|
||||||
if (m_fd == INVALID_SOCKET)
|
if (m_fd == INVALID_SOCKET)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int flag = 1;
|
int flag = 1;
|
||||||
setsockopt(m_fd, SOL_SOCKET, SO_REUSEADDR, (char*)&flag, sizeof(int));
|
setsockopt(m_fd, SOL_SOCKET, SO_REUSEADDR, (char*)&flag, sizeof(int));
|
||||||
|
|
||||||
struct sockaddr *myaddr;
|
struct sockaddr *myaddr;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
addr_man.Build(myaddr, len);
|
addr_man.Build(myaddr, len);
|
||||||
if (bind(m_fd, myaddr, addr_man.SockAddrLen()) < 0)
|
if (bind(m_fd, myaddr, addr_man.SockAddrLen()) < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (listen(m_fd, 5) < 0) {
|
if (listen(m_fd, 5) < 0) {
|
||||||
m_fd = INVALID_SOCKET;
|
m_fd = INVALID_SOCKET;
|
||||||
return;
|
return;
|
||||||
@@ -1126,24 +1130,24 @@ wxSocketServer::wxSocketServer(wxSockAddress& addr_man,
|
|||||||
bool wxSocketServer::AcceptWith(wxSocketBase& sock)
|
bool wxSocketServer::AcceptWith(wxSocketBase& sock)
|
||||||
{
|
{
|
||||||
int fd2;
|
int fd2;
|
||||||
|
|
||||||
if ((fd2 = accept(m_fd, 0, 0)) < 0)
|
if ((fd2 = accept(m_fd, 0, 0)) < 0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
struct linger linger;
|
struct linger linger;
|
||||||
linger.l_onoff = 0;
|
linger.l_onoff = 0;
|
||||||
linger.l_linger = 1;
|
linger.l_linger = 1;
|
||||||
|
|
||||||
setsockopt(fd2, SOL_SOCKET, SO_LINGER, (char*)&linger, sizeof(linger));
|
setsockopt(fd2, SOL_SOCKET, SO_LINGER, (char*)&linger, sizeof(linger));
|
||||||
|
|
||||||
int flag = 0;
|
int flag = 0;
|
||||||
setsockopt(fd2, SOL_SOCKET, SO_KEEPALIVE, (char*)&flag, sizeof(int));
|
setsockopt(fd2, SOL_SOCKET, SO_KEEPALIVE, (char*)&flag, sizeof(int));
|
||||||
|
|
||||||
if (!(sock.m_flags & SPEED)) {
|
if (!(sock.m_flags & SPEED)) {
|
||||||
unsigned long flag2 = 1;
|
unsigned long flag2 = 1;
|
||||||
ioctl(fd2, FIONBIO, &flag2);
|
ioctl(fd2, FIONBIO, &flag2);
|
||||||
}
|
}
|
||||||
|
|
||||||
sock.m_type = SOCK_INTERNAL;
|
sock.m_type = SOCK_INTERNAL;
|
||||||
sock.m_fd = fd2;
|
sock.m_fd = fd2;
|
||||||
sock.m_connected = TRUE;
|
sock.m_connected = TRUE;
|
||||||
@@ -1205,21 +1209,21 @@ bool wxSocketClient::Connect(wxSockAddress& addr_man, bool WXUNUSED(wait) )
|
|||||||
Close();
|
Close();
|
||||||
|
|
||||||
m_fd = socket(addr_man.GetFamily(), SOCK_STREAM, 0);
|
m_fd = socket(addr_man.GetFamily(), SOCK_STREAM, 0);
|
||||||
|
|
||||||
if (m_fd < 0)
|
if (m_fd < 0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
m_connected = FALSE;
|
m_connected = FALSE;
|
||||||
|
|
||||||
linger.l_onoff = 1;
|
linger.l_onoff = 1;
|
||||||
linger.l_linger = 5;
|
linger.l_linger = 5;
|
||||||
setsockopt(m_fd, SOL_SOCKET, SO_LINGER, (char*)&linger, sizeof(linger));
|
setsockopt(m_fd, SOL_SOCKET, SO_LINGER, (char*)&linger, sizeof(linger));
|
||||||
|
|
||||||
// Stay in touch with the state of things...
|
// Stay in touch with the state of things...
|
||||||
|
|
||||||
unsigned long flag = 1;
|
unsigned long flag = 1;
|
||||||
setsockopt(m_fd, SOL_SOCKET, SO_KEEPALIVE, (char*)&flag, sizeof(int));
|
setsockopt(m_fd, SOL_SOCKET, SO_KEEPALIVE, (char*)&flag, sizeof(int));
|
||||||
|
|
||||||
// Disable the nagle algorithm, which delays sends till the
|
// Disable the nagle algorithm, which delays sends till the
|
||||||
// buffer is full (or a certain time period has passed?)...
|
// buffer is full (or a certain time period has passed?)...
|
||||||
|
|
||||||
@@ -1227,7 +1231,7 @@ bool wxSocketClient::Connect(wxSockAddress& addr_man, bool WXUNUSED(wait) )
|
|||||||
flag = 1;
|
flag = 1;
|
||||||
setsockopt(m_fd, IPPROTO_TCP, TCP_NODELAY, (char*)&flag, sizeof(int));
|
setsockopt(m_fd, IPPROTO_TCP, TCP_NODELAY, (char*)&flag, sizeof(int));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct sockaddr *remote;
|
struct sockaddr *remote;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
@@ -1240,7 +1244,7 @@ bool wxSocketClient::Connect(wxSockAddress& addr_man, bool WXUNUSED(wait) )
|
|||||||
flag = 1;
|
flag = 1;
|
||||||
ioctl(m_fd, FIONBIO, &flag);
|
ioctl(m_fd, FIONBIO, &flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
Notify(TRUE);
|
Notify(TRUE);
|
||||||
|
|
||||||
m_connected = TRUE;
|
m_connected = TRUE;
|
||||||
@@ -1250,11 +1254,11 @@ bool wxSocketClient::Connect(wxSockAddress& addr_man, bool WXUNUSED(wait) )
|
|||||||
bool wxSocketClient::WaitOnConnect(long seconds)
|
bool wxSocketClient::WaitOnConnect(long seconds)
|
||||||
{
|
{
|
||||||
int ret = _Wait(seconds, 0, REQ_CONNECT | REQ_LOST);
|
int ret = _Wait(seconds, 0, REQ_CONNECT | REQ_LOST);
|
||||||
|
|
||||||
if (ret)
|
if (ret)
|
||||||
m_connected = TRUE;
|
m_connected = TRUE;
|
||||||
|
|
||||||
return m_connected;
|
return m_connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxSocketClient::OnRequest(wxRequestEvent evt)
|
void wxSocketClient::OnRequest(wxRequestEvent evt)
|
||||||
@@ -1265,7 +1269,7 @@ void wxSocketClient::OnRequest(wxRequestEvent evt)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_waitflags = 0x40;
|
m_waitflags = 0x40;
|
||||||
m_connected = TRUE;
|
m_connected = TRUE;
|
||||||
OldOnNotify(EVT_CONNECT);
|
OldOnNotify(EVT_CONNECT);
|
||||||
DestroyCallbacks();
|
DestroyCallbacks();
|
||||||
return;
|
return;
|
||||||
@@ -1416,7 +1420,7 @@ void wxSocketHandler::UnRegister(wxSocketBase* sock)
|
|||||||
|
|
||||||
for (node = socks->First(); node; node = node->Next()) {
|
for (node = socks->First(); node; node = node->Next()) {
|
||||||
wxSocketBase* s = (wxSocketBase*)node->Data();
|
wxSocketBase* s = (wxSocketBase*)node->Data();
|
||||||
|
|
||||||
if (s == sock) {
|
if (s == sock) {
|
||||||
delete node;
|
delete node;
|
||||||
sock->DestroyCallbacks();
|
sock->DestroyCallbacks();
|
||||||
|
Reference in New Issue
Block a user