GNUPG-1-9-BRANCH gnupg/jnlib (ChangeLog w32-pth.c)
cvs user twoaday
cvs at cvs.gnupg.org
Tue Dec 14 18:42:55 CET 2004
Date: Tuesday, December 14, 2004 @ 18:47:12
Author: twoaday
Path: /cvs/gnupg/gnupg/jnlib
Tag: GNUPG-1-9-BRANCH
Modified: ChangeLog w32-pth.c
2004-12-14 Timo Schulz <twoaday at g10code.com>
* w32-pth.c (pth_kill): Just release the crit section if
pth_init was really called. And set all handles to NULL.
(_pth_strerror): New.
(do_pth_wait): Before we enter the loop we check if there
are too much events in the ring.
-----------+
ChangeLog | 8 +++
w32-pth.c | 127 +++++++++++++++++++++++++++++++++++-------------------------
2 files changed, 83 insertions(+), 52 deletions(-)
Index: gnupg/jnlib/ChangeLog
diff -u gnupg/jnlib/ChangeLog:1.3.2.24 gnupg/jnlib/ChangeLog:1.3.2.25
--- gnupg/jnlib/ChangeLog:1.3.2.24 Tue Dec 14 12:25:04 2004
+++ gnupg/jnlib/ChangeLog Tue Dec 14 18:47:12 2004
@@ -1,3 +1,11 @@
+2004-12-14 Timo Schulz <twoaday at g10code.com>
+
+ * w32-pth.c (pth_kill): Just release the crit section if
+ pth_init was really called. And set all handles to NULL.
+ (_pth_strerror): New.
+ (do_pth_wait): Before we enter the loop we check if there
+ are too much events in the ring.
+
2004-12-14 Werner Koch <wk at g10code.com>
* w32-pth.h (pth_event_occured): Removed macro.
Index: gnupg/jnlib/w32-pth.c
diff -u gnupg/jnlib/w32-pth.c:1.1.2.5 gnupg/jnlib/w32-pth.c:1.1.2.6
--- gnupg/jnlib/w32-pth.c:1.1.2.5 Tue Dec 14 15:48:57 2004
+++ gnupg/jnlib/w32-pth.c Tue Dec 14 18:47:12 2004
@@ -127,14 +127,30 @@
{
pth_signo = 0;
if (pth_signo_ev)
- CloseHandle (pth_signo_ev);
- DeleteCriticalSection (&pth_shd);
+ {
+ CloseHandle (pth_signo_ev);
+ pth_signo_ev = NULL;
+ }
+ if (pth_initialized)
+ DeleteCriticalSection (&pth_shd);
WSACleanup ();
pth_initialized = 0;
return 0;
}
+static const char *
+_pth_strerror (void)
+{
+ static char strerr[256];
+
+ FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, (int)GetLastError (),
+ MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
+ strerr, sizeof (strerr)-1, NULL);
+ return strerr;
+}
+
+
static void
enter_pth (const char *function)
{
@@ -211,7 +227,11 @@
DWORD nread = 0;
n = ReadFile ((HANDLE)fd, buffer, size, &nread, NULL);
if (!n)
- n = -1;
+ {
+ fprintf (stderr, "pth_read(%d) failed read from: %s.\n", fd,
+ _pth_strerror ());
+ n = -1;
+ }
else
n = (int)nread;
}
@@ -238,22 +258,18 @@
n = send (fd, buffer, size, 0);
if (n == -1 && WSAGetLastError () == WSAENOTSOCK)
{
- char strerr[256];
-
- FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, (int)GetLastError (),
- MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
- strerr, sizeof (strerr)-1, NULL);
- fprintf (stderr, "pth_write(%d) failed in send: %s\n", fd, strerr);
-
-
DWORD nwrite;
+
+ /* this is no real error because we first need to figure out if
+ we have a handle or a socket. */
+ /*fprintf (stderr, "pth_write(%d) failed in send: %s\n", fd,
+ _pth_strerror ());*/
+
n = WriteFile ((HANDLE)fd, buffer, size, &nwrite, NULL);
if (!n)
{
- FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL,(int)GetLastError (),
- MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
- strerr, sizeof (strerr)-1, NULL);
- fprintf (stderr, "pth_write(%d) failed in write: %s\n", fd, strerr);
+ fprintf (stderr, "pth_write(%d) failed in write: %s\n", fd,
+ _pth_strerror ());
n = -1;
}
else
@@ -344,17 +360,18 @@
(WSAGetLastError () == WSAEINPROGRESS ||
WSAGetLastError () == WSAEWOULDBLOCK))
{
- if (ev == NULL) {
- ev = do_pth_event (PTH_EVENT_FD|PTH_UNTIL_FD_READABLE|PTH_MODE_STATIC,
- &ev_key, fd);
- if (ev == NULL)
- {
- leave_pth (__FUNCTION__);
- return -1;
- }
- if (ev_extra != NULL)
- pth_event_concat (ev, ev_extra, NULL);
- }
+ if (ev == NULL)
+ {
+ ev = do_pth_event (PTH_EVENT_FD|PTH_UNTIL_FD_READABLE|
+ PTH_MODE_STATIC, &ev_key, fd);
+ if (ev == NULL)
+ {
+ leave_pth (__FUNCTION__);
+ return -1;
+ }
+ if (ev_extra != NULL)
+ pth_event_concat (ev, ev_extra, NULL);
+ }
/* Wait until accept has a chance. */
do_pth_wait (ev);
if (ev_extra != NULL)
@@ -450,14 +467,15 @@
if (ev_extra != NULL)
pth_event_concat (ev, ev_extra, NULL);
pth_wait (ev);
- if (ev_extra != NULL) {
- pth_event_isolate (ev);
- if (do_pth_event_status(ev) == PTH_STATUS_PENDING)
- {
- leave_pth (__FUNCTION__);
- return -1;
- }
- }
+ if (ev_extra != NULL)
+ {
+ pth_event_isolate (ev);
+ if (do_pth_event_status(ev) == PTH_STATUS_PENDING)
+ {
+ leave_pth (__FUNCTION__);
+ return -1;
+ }
+ }
if (!(mutex->mx_state & PTH_MUTEX_LOCKED))
break;
}
@@ -894,11 +912,14 @@
helper_thread (void * ctx)
{
struct _pth_priv_hd_s * c = ctx;
-
- leave_pth (__FUNCTION__);
- c->thread (c->arg);
- enter_pth (__FUNCTION__);
- free (c);
+
+ if (c)
+ {
+ leave_pth (__FUNCTION__);
+ c->thread (c->arg);
+ enter_pth (__FUNCTION__);
+ free (c);
+ }
ExitThread (0);
return NULL;
}
@@ -1019,7 +1040,8 @@
while (ev)
{
n = ev->next;
- CloseHandle (ev->hd); ev->hd = NULL;
+ CloseHandle (ev->hd);
+ ev->hd = NULL;
free (ev);
ev = n;
}
@@ -1028,9 +1050,9 @@
{
ev->prev->next = ev->next;
ev->next->prev = ev->prev;
- CloseHandle (ev->hd); ev->hd = NULL;
+ CloseHandle (ev->hd);
+ ev->hd = NULL;
free (ev);
-
}
return 0;
@@ -1061,14 +1083,14 @@
static int
-pth_event_count (pth_event_t ev)
+_pth_event_count (pth_event_t ev)
{
pth_event_t p;
int cnt=0;
if (!ev)
return 0;
- for (p=ev; p; p = p->next)
+ for (p = ev; p; p = p->next)
cnt++;
return cnt;
}
@@ -1103,7 +1125,10 @@
int i;
for (i=0; i < n; i++)
- CloseHandle (waitbuf[hdidx[i]]);
+ {
+ CloseHandle (waitbuf[hdidx[i]]);
+ waitbuf[hdidx[i]] = NULL;
+ }
}
@@ -1146,19 +1171,17 @@
if (!ev)
return 0;
+ n =_pth_event_count (ev);
+ if (n > MAXIMUM_WAIT_OBJECTS/2)
+ return -1;
+
attr = pth_attr_new ();
pth_attr_set (attr, PTH_ATTR_JOINABLE, 1);
pth_attr_set (attr, PTH_ATTR_STACK_SIZE, 4096);
- fprintf (stderr, "pth_wait: cnt %d\n", pth_event_count (ev));
+ fprintf (stderr, "pth_wait: cnt %lu\n", n);
for (tmp = ev; tmp; tmp = tmp->next)
{
- if (pos+1 > MAXIMUM_WAIT_OBJECTS/2)
- {
- free_helper_threads (waitbuf, hdidx, i);
- pth_attr_destroy (attr);
- return -1;
- }
switch (tmp->u_type)
{
case 0:
More information about the Gnupg-commits
mailing list