From: simon Date: Sat, 26 Aug 2006 07:41:15 +0000 (+0000) Subject: Small tweak to the new handle API: provide a `privdata' field in X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/commitdiff_plain/0e03ceff4e371364f17c49ea370b6475cb0b7230 Small tweak to the new handle API: provide a `privdata' field in each handle structure, set on initialisation and readable by an API call. git-svn-id: svn://svn.tartarus.org/sgt/putty@6798 cda61777-01e9-0310-a592-d414129be87e --- diff --git a/windows/winhandl.c b/windows/winhandl.c index 305f9971..d220e640 100644 --- a/windows/winhandl.c +++ b/windows/winhandl.c @@ -18,13 +18,6 @@ * when one completes. */ -/* - * TODO: - * - * - could do with some sort of private-data field in each handle - * structure. - */ - #include #include "putty.h" @@ -58,6 +51,7 @@ struct handle_generic { int done; /* request subthread to terminate */ int defunct; /* has the subthread already gone? */ int busy; /* operation currently in progress? */ + void *privdata; /* for client to remember who they are */ }; /* ---------------------------------------------------------------------- @@ -78,6 +72,7 @@ struct handle_input { int done; /* request subthread to terminate */ int defunct; /* has the subthread already gone? */ int busy; /* operation currently in progress? */ + void *privdata; /* for client to remember who they are */ /* * Data set by the input thread before signalling ev_to_main, @@ -165,6 +160,7 @@ struct handle_output { int done; /* request subthread to terminate */ int defunct; /* has the subthread already gone? */ int busy; /* operation currently in progress? */ + void *privdata; /* for client to remember who they are */ /* * Data set by the main thread before signalling ev_from_main, @@ -267,7 +263,8 @@ static int handle_find_evtomain(void *av, void *bv) return 0; } -struct handle *handle_input_new(HANDLE handle, handle_inputfn_t gotdata) +struct handle *handle_input_new(HANDLE handle, handle_inputfn_t gotdata, + void *privdata) { struct handle *h = snew(struct handle); @@ -280,6 +277,7 @@ struct handle *handle_input_new(HANDLE handle, handle_inputfn_t gotdata) h->u.i.defunct = FALSE; h->u.i.moribund = FALSE; h->u.i.done = FALSE; + h->u.i.privdata = privdata; if (!handles_by_evtomain) handles_by_evtomain = newtree234(handle_cmp_evtomain); @@ -293,7 +291,8 @@ struct handle *handle_input_new(HANDLE handle, handle_inputfn_t gotdata) return h; } -struct handle *handle_output_new(HANDLE handle, handle_outputfn_t sentdata) +struct handle *handle_output_new(HANDLE handle, handle_outputfn_t sentdata, + void *privdata) { struct handle *h = snew(struct handle); @@ -305,6 +304,7 @@ struct handle *handle_output_new(HANDLE handle, handle_outputfn_t sentdata) h->u.o.defunct = FALSE; h->u.o.moribund = FALSE; h->u.o.done = FALSE; + h->u.o.privdata = privdata; bufchain_init(&h->u.o.queued_data); h->u.o.sentdata = sentdata; @@ -484,3 +484,8 @@ int handle_backlog(struct handle *h) assert(h->output); return bufchain_size(&h->u.o.queued_data); } + +void *handle_get_privdata(struct handle *h) +{ + return h->u.g.privdata; +} diff --git a/windows/winplink.c b/windows/winplink.c index 4ef2c980..c784a5dc 100644 --- a/windows/winplink.c +++ b/windows/winplink.c @@ -577,8 +577,8 @@ int main(int argc, char **argv) * (The input one we leave until we're through the * authentication process.) */ - stdout_handle = handle_output_new(outhandle, stdouterr_sent); - stderr_handle = handle_output_new(errhandle, stdouterr_sent); + stdout_handle = handle_output_new(outhandle, stdouterr_sent, NULL); + stderr_handle = handle_output_new(errhandle, stdouterr_sent, NULL); main_thread_id = GetCurrentThreadId(); @@ -593,7 +593,7 @@ int main(int argc, char **argv) DWORD ticks; if (!sending && back->sendok(backhandle)) { - stdin_handle = handle_input_new(inhandle, stdin_gotdata); + stdin_handle = handle_input_new(inhandle, stdin_gotdata, NULL); sending = TRUE; } diff --git a/windows/winstuff.h b/windows/winstuff.h index 5f974dc3..afc8dde2 100644 --- a/windows/winstuff.h +++ b/windows/winstuff.h @@ -411,14 +411,17 @@ void init_ucs(Config *, struct unicode_data *); struct handle; typedef int (*handle_inputfn_t)(struct handle *h, void *data, int len); typedef void (*handle_outputfn_t)(struct handle *h, int new_backlog); -struct handle *handle_input_new(HANDLE handle, handle_inputfn_t gotdata); -struct handle *handle_output_new(HANDLE handle, handle_outputfn_t sentdata); +struct handle *handle_input_new(HANDLE handle, handle_inputfn_t gotdata, + void *privdata); +struct handle *handle_output_new(HANDLE handle, handle_outputfn_t sentdata, + void *privdata); int handle_write(struct handle *h, const void *data, int len); HANDLE *handle_get_events(int *nevents); void handle_free(struct handle *h); void handle_got_event(HANDLE event); void handle_unthrottle(struct handle *h, int backlog); int handle_backlog(struct handle *h); +void *handle_get_privdata(struct handle *h); /* * pageantc.c needs to schedule callbacks for asynchronous agent