From f6aa5130824de7f6cf2d784a844a99cc077f8237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Sat, 2 Jan 2010 19:44:25 +0000 Subject: [PATCH] [GB.NET] * NEW: Socket are blocking by default, except Socket created by ServerSocket that are non-blocking by default. * BUG: Writing too much data on a non-blocking socket raises an error now. git-svn-id: svn://localhost/gambas/trunk@2593 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- gb.net/src/CServerSocket.c | 2 ++ gb.net/src/CSocket.c | 18 +++++++++++++----- gb.net/src/CSocket.h | 4 ++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/gb.net/src/CServerSocket.c b/gb.net/src/CServerSocket.c index 46e90fb7d..09f3f26ca 100644 --- a/gb.net/src/CServerSocket.c +++ b/gb.net/src/CServerSocket.c @@ -533,6 +533,8 @@ BEGIN_METHOD_VOID(CSERVERSOCKET_Accept) } CSOCKET_init_connected(cli_obj); + // Socket returned by accept is non-blocking by default + GB.Stream.Block(&cli_obj->stream, FALSE); //cli_obj->stream._free[0]=(intptr_t)cli_obj; CServerSocket_NewChild(THIS,cli_obj); diff --git a/gb.net/src/CSocket.c b/gb.net/src/CSocket.c index 27435d01c..39f9ababb 100644 --- a/gb.net/src/CSocket.c +++ b/gb.net/src/CSocket.c @@ -431,7 +431,15 @@ int CSocket_stream_write(GB_STREAM *stream, char *buffer, int len) if (!THIS) return -1; //ioctl(THIS->socket,FIONBIO,&NoBlock); - USE_MSG_NOSIGNAL(npos=send(THIS->socket,(void*)buffer,len*sizeof(char),MSG_NOSIGNAL)); + while (len > 0) + { + USE_MSG_NOSIGNAL(npos=send(THIS->socket,(void*)buffer,len*sizeof(char),MSG_NOSIGNAL)); + fprintf(stderr, "npos = %d\n", npos); + if (npos <= 0) + break; + len -= npos; + buffer += npos; + } //NoBlock++; //ioctl(THIS->socket,FIONBIO,&NoBlock); @@ -459,9 +467,9 @@ int CSocket_stream_write(GB_STREAM *stream, char *buffer, int len) /************************************************************************** To start a UNIX connection **************************************************************************/ -int CSocket_connect_unix(void *_object,char *sPath,int lenpath) +int CSocket_connect_unix(void *_object,char *sPath, int lenpath) { - int doNotBlock = 1; + int doNotBlock = 0; if ( THIS->iStatus > 0 ) return 1; if (!sPath) return 7; @@ -502,7 +510,7 @@ int CSocket_connect_unix(void *_object,char *sPath,int lenpath) return 0; } - // Set socket to non-blocking mode, after the connect() call! + // Set socket to blocking mode, after the connect() call! ioctl(THIS->socket, FIONBIO, &doNotBlock); /* Error */ @@ -522,7 +530,7 @@ int CSocket_connect_unix(void *_object,char *sPath,int lenpath) **************************************************************************/ int CSocket_connect_socket(void *_object,char *sHost,int lenhost,int myport) { - int doNotBlock = 1; + int doNotBlock = 0; if ( THIS->iStatus > 0 ) return 1; if (!lenhost) return 9; diff --git a/gb.net/src/CSocket.h b/gb.net/src/CSocket.h index 277bc2805..b9a55043c 100644 --- a/gb.net/src/CSocket.h +++ b/gb.net/src/CSocket.h @@ -88,8 +88,8 @@ void CSocket_post_hostfound(void *_object); void CSocket_post_connected(void *_object); void CSocket_post_data_available(void *_object); // -int CSocket_connect_unix(void *_object,char *sPath,int lenpath); -int CSocket_connect_socket(void *_object,char *sHost,int lenhost,int myport); +int CSocket_connect_unix(void *_object, char *sPath, int lenpath); +int CSocket_connect_socket(void *_object, char *sHost,int lenhost,int myport); int CSocket_peek_data(void *_object,char **buf,int MaxLen); // void CSocket_stream_internal_error(void *_object,int ncode, bool post);