* 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
This commit is contained in:
Benoît Minisini 2010-01-02 19:44:25 +00:00
parent e61a0c45be
commit f6aa513082
3 changed files with 17 additions and 7 deletions

View file

@ -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);

View file

@ -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;

View file

@ -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);