Skip to content

Instantly share code, notes, and snippets.

Created June 2, 2010 12:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/422277 to your computer and use it in GitHub Desktop.
Save anonymous/422277 to your computer and use it in GitHub Desktop.
--- pfwd.c.backup 2010-03-25 15:35:29.000000000 +0900
+++ pfwd.c 2010-06-02 17:56:11.000000000 +0900
@@ -306,7 +306,6 @@
THREAD_PARAM *param = (THREAD_PARAM *)lParam;
int abort = 0;
- HANDLE handles[2];
int skcount, sksize;
int connopen;
int connected = 0;
@@ -352,12 +351,11 @@
}
connopen = 1;
- handles[0] = tld.netevent;
- handles[1] = param->event;
-
now = GETTICKCOUNT();
- while (1) {
+ while (1) {
+ int nhandles;
+ HANDLE *handles;
int n;
DWORD ticks;
@@ -367,10 +365,20 @@
} else {
ticks = INFINITE;
}
-
- n = MsgWaitForMultipleObjects(2, handles, FALSE, ticks,
- QS_POSTMESSAGE);
- if (n == WAIT_OBJECT_0 + 0) {
+
+ handles = handle_get_events(&nhandles);
+ handles = sresize(handles, nhandles+2, HANDLE);
+ handles[nhandles] = tld.netevent;
+ handles[nhandles+1] = param->event;
+ n = MsgWaitForMultipleObjects(nhandles+2, handles, FALSE, ticks,
+ QS_POSTMESSAGE);
+ if ((unsigned)(n - WAIT_OBJECT_0) < (unsigned)nhandles) {
+ handle_got_event(handles[n - WAIT_OBJECT_0]);
+ if (!connected && ssh_backend.ldisc(tld.backhandle, LD_ECHO)) {
+ connected = 1;
+ PostMessage(param->hwnd, WM_CONNECTED, 0, 0);
+ }
+ } else if (n == WAIT_OBJECT_0 + nhandles) {
WSANETWORKEVENTS things;
SOCKET socket;
extern SOCKET first_socket(int *), next_socket(int *);
@@ -434,11 +442,11 @@
if (!connected && ssh_backend.ldisc(tld.backhandle, LD_ECHO)) {
connected = 1;
PostMessage(param->hwnd, WM_CONNECTED, 0, 0);
- }
- } else if (n == WAIT_OBJECT_0 + 1) {
+ }
+ } else if (n == WAIT_OBJECT_0 + nhandles + 1) {
abort = 1;
break;
- } else if (n == WAIT_OBJECT_0 + 2) {
+ } else if (n == WAIT_OBJECT_0 + nhandles + 2) {
MSG msg;
while (PeekMessage(&msg, INVALID_HANDLE_VALUE,
WM_AGENT_CALLBACK, WM_AGENT_CALLBACK,
@@ -454,6 +462,8 @@
} else {
now = GETTICKCOUNT();
}
+
+ sfree(handles);
if (!connopen || !ssh_backend.connected(tld.backhandle)) {
break;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment