* when one completes.
*/
-/*
- * TODO:
- *
- * - could do with some sort of private-data field in each handle
- * structure.
- */
-
#include <assert.h>
#include "putty.h"
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 */
};
/* ----------------------------------------------------------------------
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,
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,
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);
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);
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);
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;
assert(h->output);
return bufchain_size(&h->u.o.queued_data);
}
+
+void *handle_get_privdata(struct handle *h)
+{
+ return h->u.g.privdata;
+}
* (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();
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;
}
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