Commit 71d504d5 authored by rswindell's avatar rswindell
Browse files

Moved socket_check() from sbbs3/main.cpp to here.

parent 8fb5b66b
......@@ -37,7 +37,9 @@
#include <stdlib.h> /* malloc/free on FreeBSD */
#include <errno.h> /* ENOMEM */
#include <stdio.h> /* SEEK_SET */
#include "gen_defs.h" /* BOOL */
#include "sockwrap.h" /* sendsocket */
#include "filewrap.h" /* filelength */
......@@ -77,3 +79,41 @@ int sendfilesocket(int sock, int file, long *offset, long count)
return(wr);
}
/* Return true if connected, optionally sets *rd_p to true if read data available */
BOOL socket_check(SOCKET sock, BOOL* rd_p)
{
char ch;
int i,rd;
fd_set socket_set;
struct timeval tv;
if(rd_p!=NULL)
*rd_p=FALSE;
if(sock==INVALID_SOCKET)
return(FALSE);
FD_ZERO(&socket_set);
FD_SET(sock,&socket_set);
tv.tv_sec=0;
tv.tv_usec=0;
i=select(sock+1,&socket_set,NULL,NULL,&tv);
if(i==SOCKET_ERROR)
return(FALSE);
if(i==0)
return(TRUE);
rd=recv(sock,&ch,1,MSG_PEEK);
if(rd==1
|| (rd==SOCKET_ERROR && ERROR_VALUE==EMSGSIZE)) {
if(rd_p!=NULL)
*rd_p=TRUE;
return(TRUE);
}
return(FALSE);
}
......@@ -111,7 +111,16 @@ static wsa_error;
#endif /* __unix__ */
int sendfilesocket(int sock, int file, long *offset, long count);
#ifdef __cplusplus
extern "C" {
#endif
int sendfilesocket(int sock, int file, long *offset, long count);
BOOL socket_check(SOCKET sock, BOOL* rd_p);
#ifdef __cplusplus
}
#endif
#ifndef SHUT_RDWR
#define SHUT_RDWR 2 /* for shutdown() */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment