aboutsummaryrefslogtreecommitdiff
path: root/tools/plink/winnet.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2012-01-24 16:46:55 +0100
committermarha <marha@users.sourceforge.net>2012-01-24 16:46:55 +0100
commit6039fd0faf73c9d6c5b2abf9d824734218ec5eee (patch)
tree88f66f9d7c4763f206de6043ef45c63b94472690 /tools/plink/winnet.c
parentb683b8f5675e280a6dd4ab82d6b9394182798b55 (diff)
downloadvcxsrv-6039fd0faf73c9d6c5b2abf9d824734218ec5eee.tar.gz
vcxsrv-6039fd0faf73c9d6c5b2abf9d824734218ec5eee.tar.bz2
vcxsrv-6039fd0faf73c9d6c5b2abf9d824734218ec5eee.zip
Update to putty 9388
Diffstat (limited to 'tools/plink/winnet.c')
-rw-r--r--tools/plink/winnet.c43
1 files changed, 42 insertions, 1 deletions
diff --git a/tools/plink/winnet.c b/tools/plink/winnet.c
index 8da79dbe7..11f9ba52e 100644
--- a/tools/plink/winnet.c
+++ b/tools/plink/winnet.c
@@ -64,6 +64,7 @@ struct Socket_tag {
char oobdata[1];
int sending_oob;
int oobinline, nodelay, keepalive, privport;
+ enum { EOF_NO, EOF_PENDING, EOF_SENT } outgoingeof;
SockAddr addr;
SockAddrStep step;
int port;
@@ -167,6 +168,7 @@ DECL_WINDOWS_FUNCTION(static, int, setsockopt,
DECL_WINDOWS_FUNCTION(static, SOCKET, socket, (int, int, int));
DECL_WINDOWS_FUNCTION(static, int, listen, (SOCKET, int));
DECL_WINDOWS_FUNCTION(static, int, send, (SOCKET, const char FAR *, int, int));
+DECL_WINDOWS_FUNCTION(static, int, shutdown, (SOCKET, int));
DECL_WINDOWS_FUNCTION(static, int, ioctlsocket,
(SOCKET, long, u_long FAR *));
DECL_WINDOWS_FUNCTION(static, SOCKET, accept,
@@ -291,6 +293,7 @@ void sk_init(void)
GET_WINDOWS_FUNCTION(winsock_module, socket);
GET_WINDOWS_FUNCTION(winsock_module, listen);
GET_WINDOWS_FUNCTION(winsock_module, send);
+ GET_WINDOWS_FUNCTION(winsock_module, shutdown);
GET_WINDOWS_FUNCTION(winsock_module, ioctlsocket);
GET_WINDOWS_FUNCTION(winsock_module, accept);
GET_WINDOWS_FUNCTION(winsock_module, recv);
@@ -745,6 +748,7 @@ static void sk_tcp_flush(Socket s)
static void sk_tcp_close(Socket s);
static int sk_tcp_write(Socket s, const char *data, int len);
static int sk_tcp_write_oob(Socket s, const char *data, int len);
+static void sk_tcp_write_eof(Socket s);
static void sk_tcp_set_private_ptr(Socket s, void *ptr);
static void *sk_tcp_get_private_ptr(Socket s);
static void sk_tcp_set_frozen(Socket s, int is_frozen);
@@ -759,6 +763,7 @@ Socket sk_register(void *sock, Plug plug)
sk_tcp_close,
sk_tcp_write,
sk_tcp_write_oob,
+ sk_tcp_write_eof,
sk_tcp_flush,
sk_tcp_set_private_ptr,
sk_tcp_get_private_ptr,
@@ -780,6 +785,7 @@ Socket sk_register(void *sock, Plug plug)
bufchain_init(&ret->output_data);
ret->writable = 1; /* to start with */
ret->sending_oob = 0;
+ ret->outgoingeof = EOF_NO;
ret->frozen = 1;
ret->frozen_readable = 0;
ret->localhost_only = 0; /* unused, but best init anyway */
@@ -1007,6 +1013,7 @@ Socket sk_new(SockAddr addr, int port, int privport, int oobinline,
sk_tcp_close,
sk_tcp_write,
sk_tcp_write_oob,
+ sk_tcp_write_eof,
sk_tcp_flush,
sk_tcp_set_private_ptr,
sk_tcp_get_private_ptr,
@@ -1028,6 +1035,7 @@ Socket sk_new(SockAddr addr, int port, int privport, int oobinline,
ret->connected = 0; /* to start with */
ret->writable = 0; /* to start with */
ret->sending_oob = 0;
+ ret->outgoingeof = EOF_NO;
ret->frozen = 0;
ret->frozen_readable = 0;
ret->localhost_only = 0; /* unused, but best init anyway */
@@ -1058,6 +1066,7 @@ Socket sk_newlistener(char *srcaddr, int port, Plug plug, int local_host_only,
sk_tcp_close,
sk_tcp_write,
sk_tcp_write_oob,
+ sk_tcp_write_eof,
sk_tcp_flush,
sk_tcp_set_private_ptr,
sk_tcp_get_private_ptr,
@@ -1089,6 +1098,7 @@ Socket sk_newlistener(char *srcaddr, int port, Plug plug, int local_host_only,
bufchain_init(&ret->output_data);
ret->writable = 0; /* to start with */
ret->sending_oob = 0;
+ ret->outgoingeof = EOF_NO;
ret->frozen = 0;
ret->frozen_readable = 0;
ret->localhost_only = local_host_only;
@@ -1325,12 +1335,23 @@ void try_send(Actual_Socket s)
}
}
}
+
+ /*
+ * If we reach here, we've finished sending everything we might
+ * have needed to send. Send EOF, if we need to.
+ */
+ if (s->outgoingeof == EOF_PENDING) {
+ p_shutdown(s->s, SD_SEND);
+ s->outgoingeof = EOF_SENT;
+ }
}
static int sk_tcp_write(Socket sock, const char *buf, int len)
{
Actual_Socket s = (Actual_Socket) sock;
+ assert(s->outgoingeof == EOF_NO);
+
/*
* Add the data to the buffer list on the socket.
*/
@@ -1349,6 +1370,8 @@ static int sk_tcp_write_oob(Socket sock, const char *buf, int len)
{
Actual_Socket s = (Actual_Socket) sock;
+ assert(s->outgoingeof == EOF_NO);
+
/*
* Replace the buffer list on the socket with the data.
*/
@@ -1366,6 +1389,24 @@ static int sk_tcp_write_oob(Socket sock, const char *buf, int len)
return s->sending_oob;
}
+static void sk_tcp_write_eof(Socket sock)
+{
+ Actual_Socket s = (Actual_Socket) sock;
+
+ assert(s->outgoingeof == EOF_NO);
+
+ /*
+ * Mark the socket as pending outgoing EOF.
+ */
+ s->outgoingeof = EOF_PENDING;
+
+ /*
+ * Now try sending from the start of the buffer list.
+ */
+ if (s->writable)
+ try_send(s);
+}
+
int select_result(WPARAM wParam, LPARAM lParam)
{
int ret, open;
@@ -1691,7 +1732,7 @@ char *get_hostname(void)
hostname = NULL;
break;
}
- } while (strlen(hostname) >= len-1);
+ } while (strlen(hostname) >= (size_t)(len-1));
return hostname;
}