1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-02 03:52:49 -05:00

Replace the hacky 'OSSocket' type with a closure.

The mechanism for constructing a new connection-type Socket when a
listening one receives an incoming connection previously worked by
passing a platform-specific 'OSSocket' type to the plug_accepting
function, which would then call sk_register to wrap it with a proper
Socket instance. This is less flexible than ideal, because it presumes
that only one kind of OS object might ever need to be turned into a
Socket. So I've replaced OSSocket throughout the code base with a pair
of parameters consisting of a function pointer and a context such that
passing the latter to the former returns the appropriate Socket; this
will permit different classes of listening Socket to pass different
function pointers.

In deference to the reality that OSSockets tend to be small integers
or pointer-sized OS handles, I've made the context parameter an
int/pointer union that can hold either of those directly, rather than
the usual approach of making it a plain 'void *' and requiring a
context structure to be dynamically allocated every time.

[originally from svn r10068]
This commit is contained in:
Simon Tatham
2013-11-17 14:03:55 +00:00
parent 9093071faa
commit 19fba3fe55
8 changed files with 39 additions and 28 deletions

20
proxy.c
View File

@ -261,16 +261,18 @@ static void plug_proxy_sent (Plug p, int bufsize)
plug_sent(ps->plug, bufsize);
}
static int plug_proxy_accepting (Plug p, OSSocket sock)
static int plug_proxy_accepting(Plug p,
accept_fn_t constructor, accept_ctx_t ctx)
{
Proxy_Plug pp = (Proxy_Plug) p;
Proxy_Socket ps = pp->proxy_socket;
if (ps->state != PROXY_STATE_ACTIVE) {
ps->accepting_sock = sock;
ps->accepting_constructor = constructor;
ps->accepting_ctx = ctx;
return ps->negotiate(ps, PROXY_CHANGE_ACCEPTING);
}
return plug_accepting(ps->plug, sock);
return plug_accepting(ps->plug, constructor, ctx);
}
/*
@ -617,7 +619,8 @@ int proxy_http_negotiate (Proxy_Socket p, int change)
* what should we do? close the socket with an appropriate
* error message?
*/
return plug_accepting(p->plug, p->accepting_sock);
return plug_accepting(p->plug,
p->accepting_constructor, p->accepting_ctx);
}
if (change == PROXY_CHANGE_RECEIVE) {
@ -819,7 +822,8 @@ int proxy_socks4_negotiate (Proxy_Socket p, int change)
* what should we do? close the socket with an appropriate
* error message?
*/
return plug_accepting(p->plug, p->accepting_sock);
return plug_accepting(p->plug,
p->accepting_constructor, p->accepting_ctx);
}
if (change == PROXY_CHANGE_RECEIVE) {
@ -958,7 +962,8 @@ int proxy_socks5_negotiate (Proxy_Socket p, int change)
* what should we do? close the socket with an appropriate
* error message?
*/
return plug_accepting(p->plug, p->accepting_sock);
return plug_accepting(p->plug,
p->accepting_constructor, p->accepting_ctx);
}
if (change == PROXY_CHANGE_RECEIVE) {
@ -1496,7 +1501,8 @@ int proxy_telnet_negotiate (Proxy_Socket p, int change)
* what should we do? close the socket with an appropriate
* error message?
*/
return plug_accepting(p->plug, p->accepting_sock);
return plug_accepting(p->plug,
p->accepting_constructor, p->accepting_ctx);
}
if (change == PROXY_CHANGE_RECEIVE) {