socket fixes
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@459 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
b46d033b12
commit
83c4fab84c
@ -1092,11 +1092,18 @@ SocketGetc(int sno)
|
|||||||
count = read(s->u.socket.fd, &c, sizeof(char));
|
count = read(s->u.socket.fd, &c, sizeof(char));
|
||||||
#endif
|
#endif
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
|
s->u.socket.flags = closed_socket;
|
||||||
ch = EOF;
|
ch = EOF;
|
||||||
} else if (count > 0) {
|
} else if (count > 0) {
|
||||||
ch = c;
|
ch = c;
|
||||||
} else {
|
} else {
|
||||||
Error(SYSTEM_ERROR, TermNil, "read");
|
#if HAVE_STRERROR
|
||||||
|
Error(SYSTEM_ERROR, TermNil,
|
||||||
|
"( socket_getc: %s)", strerror(errno));
|
||||||
|
#else
|
||||||
|
Error(SYSTEM_ERROR, TermNil,
|
||||||
|
"(socket_getc)");
|
||||||
|
#endif
|
||||||
return(EOF);
|
return(EOF);
|
||||||
}
|
}
|
||||||
return(post_process_read_char(ch, s, sno));
|
return(post_process_read_char(ch, s, sno));
|
||||||
|
44
C/ypsocks.c
44
C/ypsocks.c
@ -450,7 +450,42 @@ p_socket(void)
|
|||||||
Int
|
Int
|
||||||
CloseSocket(int fd, socket_info status, socket_domain domain)
|
CloseSocket(int fd, socket_info status, socket_domain domain)
|
||||||
{
|
{
|
||||||
if (domain == client_socket || domain == server_session_socket) {
|
#if _MSC_VER || defined(__MINGW32__)
|
||||||
|
/* prevent further writing
|
||||||
|
to the socket */
|
||||||
|
if (status == server_session_socket ||
|
||||||
|
status == client_socket) {
|
||||||
|
char bfr;
|
||||||
|
|
||||||
|
if (shutdown(fd, 1) != 0) {
|
||||||
|
Error(SYSTEM_ERROR, TermNil,
|
||||||
|
"socket_close/1 (close)");
|
||||||
|
return(FALSE);
|
||||||
|
}
|
||||||
|
/* read all pending characters
|
||||||
|
from the socket */
|
||||||
|
while( recv( fd, &bfr, 1, 0 ) > 0 );
|
||||||
|
/* prevent further reading
|
||||||
|
from the socket */
|
||||||
|
if (shutdown(fd, 0) < 0) {
|
||||||
|
Error(SYSTEM_ERROR, TermNil,
|
||||||
|
"socket_close/1 (close)");
|
||||||
|
return(FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* close the socket */
|
||||||
|
if (closesocket(fd) != 0) {
|
||||||
|
#if HAVE_STRERROR
|
||||||
|
Error(SYSTEM_ERROR, TermNil,
|
||||||
|
"socket_close/1 (close: %s)", strerror(socket_errno));
|
||||||
|
#else
|
||||||
|
Error(SYSTEM_ERROR, TermNil,
|
||||||
|
"socket_close/1 (close)");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (status == server_session_socket ||
|
||||||
|
status == client_socket) {
|
||||||
if (shutdown(fd,2) < 0) {
|
if (shutdown(fd,2) < 0) {
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
Error(SYSTEM_ERROR, TermNil,
|
Error(SYSTEM_ERROR, TermNil,
|
||||||
@ -462,17 +497,14 @@ CloseSocket(int fd, socket_info status, socket_domain domain)
|
|||||||
return(FALSE);
|
return(FALSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if _MSC_VER || defined(__MINGW32__)
|
if (close(fd) != 0) {
|
||||||
if (closesocket(fd) != 0) {
|
|
||||||
#else
|
|
||||||
if (close(fd) < 0) {
|
|
||||||
#endif
|
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
Error(SYSTEM_ERROR, TermNil,
|
Error(SYSTEM_ERROR, TermNil,
|
||||||
"socket_close/1 (close: %s)", strerror(socket_errno));
|
"socket_close/1 (close: %s)", strerror(socket_errno));
|
||||||
#else
|
#else
|
||||||
Error(SYSTEM_ERROR, TermNil,
|
Error(SYSTEM_ERROR, TermNil,
|
||||||
"socket_close/1 (close)");
|
"socket_close/1 (close)");
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
}
|
}
|
||||||
|
@ -221,7 +221,8 @@ typedef enum{ /* in YAP, sockets may be in one of 4 possible status */
|
|||||||
new_socket,
|
new_socket,
|
||||||
server_socket,
|
server_socket,
|
||||||
client_socket,
|
client_socket,
|
||||||
server_session_socket
|
server_session_socket,
|
||||||
|
closed_socket
|
||||||
} socket_info;
|
} socket_info;
|
||||||
|
|
||||||
typedef enum{ /* we accept two domains for the moment, IPV6 may follow */
|
typedef enum{ /* we accept two domains for the moment, IPV6 may follow */
|
||||||
|
Reference in New Issue
Block a user