|
From: Andreas R. <and...@us...> - 2002-05-04 23:20:31
|
Update of /cvsroot/squeak/squeak/platforms/win32/plugins/SocketPlugin
In directory usw-pr-cvs1:/tmp/cvs-serv7733/plugins/SocketPlugin
Modified Files:
sqWin32NewNet.c
Log Message:
Update to 3.2.1
Index: sqWin32NewNet.c
===================================================================
RCS file: /cvsroot/squeak/squeak/platforms/win32/plugins/SocketPlugin/sqWin32NewNet.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** sqWin32NewNet.c 24 Oct 2001 23:14:25 -0000 1.1.1.1
--- sqWin32NewNet.c 4 May 2002 23:20:28 -0000 1.2
***************
*** 139,142 ****
--- 139,145 ----
#define ADDRESS(s) ((struct sockaddr_in*)(&PSP(s)->peer))
+ extern struct VirtualMachine *interpreterProxy;
+ #define FAIL() interpreterProxy->primitiveFail()
+
#define LOCKSOCKET(mutex, duration) \
if(WaitForSingleObject(mutex, duration) == WAIT_FAILED)\
***************
*** 189,192 ****
--- 192,196 ----
}
}
+
/* cleanupSocket:
Clean up the private socket structure and associated elements.
***************
*** 220,223 ****
--- 224,228 ----
setsockopt(temp->s, SOL_SOCKET, SO_LINGER, (char*)&l, sizeof(l));
closesocket(temp->s);
+ temp->s = NULL;
GlobalFree(GlobalHandle(temp));
}
***************
*** 247,250 ****
--- 252,256 ----
ioctlsocket(newSocket,FIONBIO,&zero);
closesocket(pss->s);
+ pss->s = 0;
/* Disable TCP delays */
setsockopt(newSocket, IPPROTO_TCP, TCP_NODELAY, (char*) &one, sizeof(one));
***************
*** 440,443 ****
--- 446,450 ----
pss->sockState = ThisEndClosed;
pss->readWatcherOp = 0; /* since a close succeeded */
+ pss->s = NULL;
doWait = 1;
break;
***************
*** 512,515 ****
--- 519,523 ----
} else {
/* get socket error */
+ /* printf("ERROR: %d\n", WSAGetLastError()); */
errSize = sizeof(pss->sockError);
getsockopt(pss->s, SOL_SOCKET, SO_ERROR, (char*)&pss->sockError, &errSize);
***************
*** 717,721 ****
return true;
} else {
! success(false);
return false;
}
--- 725,729 ----
return true;
} else {
! FAIL();
return false;
}
***************
*** 757,760 ****
--- 765,769 ----
}
} else {
+ pss->s = NULL;
pss->sockState = Unconnected;
}
***************
*** 768,771 ****
--- 777,781 ----
setsockopt(temp->s, SOL_SOCKET, SO_LINGER, (char*)&l, sizeof(l));
closesocket(temp->s);
+ temp->s = 0;
GlobalFree(GlobalHandle(temp));
}
***************
*** 817,821 ****
err = WSAGetLastError();
if(err != WSAEWOULDBLOCK) {
! success(false);
return;
}
--- 827,831 ----
err = WSAGetLastError();
if(err != WSAEWOULDBLOCK) {
! FAIL();
return;
}
***************
*** 843,846 ****
--- 853,857 ----
void sqSocketListenOnPort(SocketPtr s, int port)
{
+ int result;
struct sockaddr_in addr;
privateSocketStruct *pss = PSP(s);
***************
*** 858,866 ****
} else { /* TCP */
/* show our willingness to accept a single incoming connection */
! listen(SOCKET(s), 1);
! /* Waiting for accept => Start read watcher */
! pss->sockState = WaitingForConnection;
! pss->readWatcherOp = WatchAcceptSingle;
! SetEvent(pss->hReadWatcherEvent);
}
}
--- 869,881 ----
} else { /* TCP */
/* show our willingness to accept a single incoming connection */
! result = listen(SOCKET(s), 1);
! if(result == SOCKET_ERROR) {
! FAIL();
! } else {
! /* Waiting for accept => Start read watcher */
! pss->sockState = WaitingForConnection;
! pss->readWatcherOp = WatchAcceptSingle;
! SetEvent(pss->hReadWatcherEvent);
! }
}
}
***************
*** 873,876 ****
--- 888,892 ----
void sqSocketListenOnPortBacklogSize(SocketPtr s, int port, int backlogSize)
{
+ int result;
struct sockaddr_in addr;
privateSocketStruct *pss = PSP(s);
***************
*** 891,901 ****
bind( SOCKET(s), (struct sockaddr*) &addr, sizeof(struct sockaddr_in));
/* show our willingness to accept a backlogSize incoming connections */
! listen(SOCKET(s), backlogSize);
! LOCKSOCKET(pss->mutex, INFINITE);
! /* Waiting for accept => Start read watcher */
! pss->sockState = WaitingForConnection;
! pss->readWatcherOp = WatchAccept;
! SetEvent(pss->hReadWatcherEvent);
! UNLOCKSOCKET(pss->mutex);
}
--- 907,921 ----
bind( SOCKET(s), (struct sockaddr*) &addr, sizeof(struct sockaddr_in));
/* show our willingness to accept a backlogSize incoming connections */
! result = listen(SOCKET(s), backlogSize);
! if(result != SOCKET_ERROR) {
! LOCKSOCKET(pss->mutex, INFINITE);
! /* Waiting for accept => Start read watcher */
! pss->sockState = WaitingForConnection;
! pss->readWatcherOp = WatchAccept;
! SetEvent(pss->hReadWatcherEvent);
! UNLOCKSOCKET(pss->mutex);
! } else {
! FAIL();
! }
}
***************
*** 919,925 ****
else if(socketType == UDPSocketType)
newSocket = socket(AF_INET, SOCK_DGRAM, 0);
! else { success(false); return; }
if(newSocket == INVALID_SOCKET) {
! success(false);
return;
}
--- 939,945 ----
else if(socketType == UDPSocketType)
newSocket = socket(AF_INET, SOCK_DGRAM, 0);
! else { FAIL(); return; }
if(newSocket == INVALID_SOCKET) {
! FAIL();
return;
}
***************
*** 958,962 ****
/* Create a new mutex object for synchronized access */
pss->mutex = CreateMutex(NULL, 0,NULL);
! if(!pss->mutex) { success(false); return; }
/* Install the socket into the socket list */
--- 978,982 ----
/* Create a new mutex object for synchronized access */
pss->mutex = CreateMutex(NULL, 0,NULL);
! if(!pss->mutex) { FAIL(); return; }
/* Install the socket into the socket list */
***************
*** 972,976 ****
/* note: necessary cleanup is done from within createWatcherThreads */
s->privateSocketPtr = NULL; /* declare invalid */
! primitiveFail();
}
}
--- 992,996 ----
/* note: necessary cleanup is done from within createWatcherThreads */
s->privateSocketPtr = NULL; /* declare invalid */
! FAIL();
}
}
***************
*** 1005,1013 ****
if(!accepted) { /* something was wrong here */
! success(false);
return;
}
if(accepted->s == INVALID_SOCKET) {
! success(false);
return;
}
--- 1025,1033 ----
if(!accepted) { /* something was wrong here */
! FAIL();
return;
}
if(accepted->s == INVALID_SOCKET) {
! FAIL();
return;
}
***************
*** 1033,1037 ****
/* Create a new mutex object for synchronized access */
pss->mutex = CreateMutex(NULL, 0,NULL);
! if(!pss->mutex) { success(false); return; }
/* Install the socket into the socket list */
--- 1053,1057 ----
/* Create a new mutex object for synchronized access */
pss->mutex = CreateMutex(NULL, 0,NULL);
! if(!pss->mutex) { FAIL(); return; }
/* Install the socket into the socket list */
***************
*** 1045,1049 ****
/* note: necessary cleanup is done from within createWatcherThreads */
s->privateSocketPtr = NULL; /* declare invalid */
! primitiveFail();
}
--- 1065,1069 ----
/* note: necessary cleanup is done from within createWatcherThreads */
s->privateSocketPtr = NULL; /* declare invalid */
! FAIL();
}
***************
*** 1128,1138 ****
/* Guard eventual writes to socket state */
LOCKSOCKET(pss->mutex, INFINITE)
! if(result == 0)
! pss->sockState = OtherEndClosed;
! else if(result < 0) {
! int err = WSAGetLastError();
! if(err == WSAECONNRESET) /* connection reset by peer */
pss->sockState = OtherEndClosed;
! else if(err == WSAEWOULDBLOCK) {
/* no data available -> wake up read watcher */
pss->sockState &= ~SOCK_DATA_READABLE;
--- 1148,1158 ----
/* Guard eventual writes to socket state */
LOCKSOCKET(pss->mutex, INFINITE)
! if(result == 0) {
! /* UDP doesn't know "other end closed" state */
! if(pss->sockType != UDPSocketType)
pss->sockState = OtherEndClosed;
! } else if(result < 0) {
! int err = WSAGetLastError();
! if(err == WSAEWOULDBLOCK) {
/* no data available -> wake up read watcher */
pss->sockState &= ~SOCK_DATA_READABLE;
***************
*** 1140,1143 ****
--- 1160,1170 ----
SetEvent(pss->hReadWatcherEvent);
} else {
+ /* printf("ERROR: %d\n", err); */
+ /* NOTE: We consider all other errors to be fatal, e.g.,
+ report them as "other end closed". Looking at the
+ WSock documentation this ought to be correct. */
+ /* UDP doesn't know "other end closed" state */
+ if(pss->sockType != UDPSocketType)
+ pss->sockState = OtherEndClosed;
pss->sockError = err;
}
***************
*** 1196,1211 ****
/* Guard eventual writes to socket state */
LOCKSOCKET(pss->mutex, INFINITE)
! /***NOTE***NOTE***NOTE***NOTE***NOTE***
! It's clear that for a write result being
! equal to zero the other side must have
! closed down (since we're rejecting zero
! writes above) but nevertheless keep it
! in mind if you change the above...
! **************************************/
! if(result == SOCKET_ERROR) {
! int err = WSAGetLastError();
! if(err == WSAECONNRESET) /* connection reset by peer */
pss->sockState = OtherEndClosed;
! else if(err == WSAEWOULDBLOCK) {
/* no data available => wake up write watcher */
pss->sockState &= ~SOCK_DATA_WRITABLE;
--- 1223,1233 ----
/* Guard eventual writes to socket state */
LOCKSOCKET(pss->mutex, INFINITE)
! if(result == 0) {
! /* UDP doesn't know "other end closed" state */
! if(pss->sockType != UDPSocketType)
pss->sockState = OtherEndClosed;
! } else {
! int err = WSAGetLastError();
! if(err == WSAEWOULDBLOCK) {
/* no data available => wake up write watcher */
pss->sockState &= ~SOCK_DATA_WRITABLE;
***************
*** 1213,1216 ****
--- 1235,1245 ----
SetEvent(pss->hWriteWatcherEvent);
} else {
+ /* printf("ERROR: %d\n", err); */
+ /* NOTE: We consider all other errors to be fatal, e.g.,
+ report them as "other end closed". Looking at the
+ WSock documentation this ought to be correct. */
+ /* UDP doesn't know "other end closed" state */
+ if(pss->sockType != UDPSocketType)
+ pss->sockState = OtherEndClosed;
pss->sockError = err;
}
***************
*** 1306,1310 ****
int recvBufSize, int sendBufSize, int semaIndex, int readSemaIndex, int writeSemaIndex)
{
! primitiveFail();
}
--- 1335,1339 ----
int recvBufSize, int sendBufSize, int semaIndex, int readSemaIndex, int writeSemaIndex)
{
! FAIL();
}
***************
*** 1313,1327 ****
int recvBufSize, int sendBufSize, int semaIndex, int readSemaIndex, int writeSemaIndex)
{
! primitiveFail();
}
int sqSocketReceiveUDPDataBufCountaddressportmoreFlag(SocketPtr s, int buf, int bufSize, int *address, int *port, int *moreFlag)
{
! return primitiveFail();
}
int sqSockettoHostportSendDataBufCount(SocketPtr s, int address, int port, int buf, int bufSize)
{
! return primitiveFail();
}
--- 1342,1356 ----
int recvBufSize, int sendBufSize, int semaIndex, int readSemaIndex, int writeSemaIndex)
{
! FAIL();
}
int sqSocketReceiveUDPDataBufCountaddressportmoreFlag(SocketPtr s, int buf, int bufSize, int *address, int *port, int *moreFlag)
{
! return FAIL();
}
int sqSockettoHostportSendDataBufCount(SocketPtr s, int address, int port, int buf, int bufSize)
{
! return FAIL();
}
***************
*** 1329,1333 ****
SocketPtr s,int optionName, int optionNameSize, int optionValue, int optionValueSize, int *result)
{
! return primitiveFail();
}
--- 1358,1362 ----
SocketPtr s,int optionName, int optionNameSize, int optionValue, int optionValueSize, int *result)
{
! return FAIL();
}
***************
*** 1335,1339 ****
SocketPtr s,int optionName, int optionNameSize, int *result)
{
! return primitiveFail();
}
--- 1364,1368 ----
SocketPtr s,int optionName, int optionNameSize, int *result)
{
! return FAIL();
}
|