From 9545199ea5edb6f7b0fedd27855ab9e467b6f6da Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 28 Jul 2019 10:32:17 +0100 Subject: [PATCH] Completely remove sk_flush(). I've only just noticed that it doesn't do anything at all! Almost every implementation of the Socket vtable provides a flush() method which does nothing, optionally with a comment explaining why it's OK to do nothing. The sole exception is the wrapper Proxy_Socket, which implements the method during its setup phase by setting a pending_flush flag, so that when its sub-socket is later created, it can call sk_flush on that. But since the sub-socket's sk_flush will do nothing, even that is completely pointless! Source control history says that sk_flush was introduced by Dave Hinton in 2001 (commit 7b0e08270), who was going to use it for some purpose involving the SSL Telnet support he was working on at the time. That SSL support was never finished, and its vestigial declarations in network.h were removed in 2015 (commit 42334b65b). So sk_flush is just another vestige of that abandoned work, which I should have removed in the latter commit but overlooked. --- errsock.c | 1 - network.h | 3 --- proxy.c | 18 ------------------ unix/uxfdsock.c | 7 ------- unix/uxnet.c | 9 --------- windows/winhsock.c | 7 ------- windows/winnet.c | 9 --------- windows/winnps.c | 3 +-- 8 files changed, 1 insertion(+), 56 deletions(-) diff --git a/errsock.c b/errsock.c index 9ab7c3db..e691dec2 100644 --- a/errsock.c +++ b/errsock.c @@ -50,7 +50,6 @@ static const SocketVtable ErrorSocket_sockvt = { NULL /* write */, NULL /* write_oob */, NULL /* write_eof */, - NULL /* flush */, NULL /* set_frozen */, sk_error_socket_error, sk_error_peer_info, diff --git a/network.h b/network.h index 689b4c5f..b86c054a 100644 --- a/network.h +++ b/network.h @@ -31,7 +31,6 @@ struct SocketVtable { size_t (*write) (Socket *s, const void *data, size_t len); size_t (*write_oob) (Socket *s, const void *data, size_t len); void (*write_eof) (Socket *s); - void (*flush) (Socket *s); void (*set_frozen) (Socket *s, bool is_frozen); /* ignored by tcp, but vital for ssl */ const char *(*socket_error) (Socket *s); @@ -158,8 +157,6 @@ static inline size_t sk_write_oob(Socket *s, const void *data, size_t len) { return s->vt->write_oob(s, data, len); } static inline void sk_write_eof(Socket *s) { s->vt->write_eof(s); } -static inline void sk_flush(Socket *s) -{ s->vt->flush(s); } static inline void plug_log( Plug *p, int type, SockAddr *addr, int port, const char *msg, int code) diff --git a/proxy.c b/proxy.c index e9ab244d..c3bea773 100644 --- a/proxy.c +++ b/proxy.c @@ -57,11 +57,6 @@ void proxy_activate (ProxySocket *p) if (output_after < output_before) plug_sent(p->plug, output_after); - /* if we were asked to flush the output during - * the proxy negotiation process, do so now. - */ - if (p->pending_flush) sk_flush(p->sub_socket); - /* if we have a pending EOF to send, send it */ if (p->pending_eof) sk_write_eof(p->sub_socket); @@ -128,17 +123,6 @@ static void sk_proxy_write_eof (Socket *s) sk_write_eof(ps->sub_socket); } -static void sk_proxy_flush (Socket *s) -{ - ProxySocket *ps = container_of(s, ProxySocket, sock); - - if (ps->state != PROXY_STATE_ACTIVE) { - ps->pending_flush = true; - return; - } - sk_flush(ps->sub_socket); -} - static void sk_proxy_set_frozen (Socket *s, bool is_frozen) { ProxySocket *ps = container_of(s, ProxySocket, sock); @@ -393,7 +377,6 @@ static const struct SocketVtable ProxySocket_sockvt = { sk_proxy_write, sk_proxy_write_oob, sk_proxy_write_eof, - sk_proxy_flush, sk_proxy_set_frozen, sk_proxy_socket_error, NULL, /* peer_info */ @@ -437,7 +420,6 @@ Socket *new_connection(SockAddr *addr, const char *hostname, ret->remote_port = port; ret->error = NULL; - ret->pending_flush = false; ret->pending_eof = false; ret->freeze = false; diff --git a/unix/uxfdsock.c b/unix/uxfdsock.c index b6b43fa2..c7cab247 100644 --- a/unix/uxfdsock.c +++ b/unix/uxfdsock.c @@ -229,12 +229,6 @@ static void fdsocket_write_eof(Socket *s) fdsocket_try_send(fds); } -static void fdsocket_flush(Socket *s) -{ - /* FdSocket *fds = container_of(s, FdSocket, sock); */ - /* do nothing */ -} - static void fdsocket_set_frozen(Socket *s, bool is_frozen) { FdSocket *fds = container_of(s, FdSocket, sock); @@ -315,7 +309,6 @@ static const SocketVtable FdSocket_sockvt = { fdsocket_write, fdsocket_write_oob, fdsocket_write_eof, - fdsocket_flush, fdsocket_set_frozen, fdsocket_socket_error, NULL, /* peer_info */ diff --git a/unix/uxnet.c b/unix/uxnet.c index ef452d3d..3b55772e 100644 --- a/unix/uxnet.c +++ b/unix/uxnet.c @@ -492,14 +492,6 @@ static Plug *sk_net_plug(Socket *sock, Plug *p) return ret; } -static void sk_net_flush(Socket *s) -{ - /* - * We send data to the socket as soon as we can anyway, - * so we don't need to do anything here. :-) - */ -} - static void sk_net_close(Socket *s); static size_t sk_net_write(Socket *s, const void *data, size_t len); static size_t sk_net_write_oob(Socket *s, const void *data, size_t len); @@ -514,7 +506,6 @@ static struct SocketVtable NetSocket_sockvt = { sk_net_write, sk_net_write_oob, sk_net_write_eof, - sk_net_flush, sk_net_set_frozen, sk_net_socket_error, sk_net_peer_info, diff --git a/windows/winhsock.c b/windows/winhsock.c index 7f2b4474..aa3b5a9f 100644 --- a/windows/winhsock.c +++ b/windows/winhsock.c @@ -156,12 +156,6 @@ static void sk_handle_write_eof(Socket *s) handle_write_eof(hs->send_h); } -static void sk_handle_flush(Socket *s) -{ - /* HandleSocket *hs = container_of(s, HandleSocket, sock); */ - /* do nothing */ -} - static void handle_socket_unfreeze(void *hsv) { HandleSocket *hs = (HandleSocket *)hsv; @@ -315,7 +309,6 @@ static const SocketVtable HandleSocket_sockvt = { sk_handle_write, sk_handle_write_oob, sk_handle_write_eof, - sk_handle_flush, sk_handle_set_frozen, sk_handle_socket_error, sk_handle_peer_info, diff --git a/windows/winnet.c b/windows/winnet.c index ae5b11f6..535e37b9 100644 --- a/windows/winnet.c +++ b/windows/winnet.c @@ -823,14 +823,6 @@ static Plug *sk_net_plug(Socket *sock, Plug *p) return ret; } -static void sk_net_flush(Socket *s) -{ - /* - * We send data to the socket as soon as we can anyway, - * so we don't need to do anything here. :-) - */ -} - static void sk_net_close(Socket *s); static size_t sk_net_write(Socket *s, const void *data, size_t len); static size_t sk_net_write_oob(Socket *s, const void *data, size_t len); @@ -845,7 +837,6 @@ static const SocketVtable NetSocket_sockvt = { sk_net_write, sk_net_write_oob, sk_net_write_eof, - sk_net_flush, sk_net_set_frozen, sk_net_socket_error, sk_net_peer_info, diff --git a/windows/winnps.c b/windows/winnps.c index fa1d804b..5c201641 100644 --- a/windows/winnps.c +++ b/windows/winnps.c @@ -192,7 +192,7 @@ static void named_pipe_connect_callback(void *vps) /* * This socket type is only used for listening, so it should never - * be asked to write or flush or set_frozen. + * be asked to write or set_frozen. */ static const SocketVtable NamedPipeServerSocket_sockvt = { sk_namedpipeserver_plug, @@ -200,7 +200,6 @@ static const SocketVtable NamedPipeServerSocket_sockvt = { NULL /* write */, NULL /* write_oob */, NULL /* write_eof */, - NULL /* flush */, NULL /* set_frozen */, sk_namedpipeserver_socket_error, sk_namedpipeserver_peer_info,