aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2014-05-02 06:06:10 +0000
committerWerner Koch <[email protected]>2014-05-02 06:22:38 +0000
commit84289e85c72ae58c321dfdb96816700a6b7f7122 (patch)
treeb5df413e25fd8e72702e23a4efc36813475d5075
parentestream: Implement "samethread" mode keyword. (diff)
downloadgnupg-84289e85c72ae58c321dfdb96816700a6b7f7122.tar.gz
gnupg-84289e85c72ae58c321dfdb96816700a6b7f7122.zip
common: Cleanup the use of USE_NPTH and HAVE_NPTH macros.
* configure.ac (HAVE_NPTH): New ac_define. * common/estream.c: Use USE_NPTH instead of HAVE_NPTH. * common/http.c: Ditto. Replace remaining calls to pth by npth calls. (connect_server): Remove useless _(). * common/exechelp-posix.c, common/exechelp-w32.c * common/exechelp-w32ce.c: Use HAVE_PTH to include npth.h. * common/init.c (_init_common_subsystems): Remove call to pth_init. * common/sysutils.c (gnupg_sleep): Use npth_sleep. * scd/ccid-driver.c (my_sleep): Ditto. -- USE_NPTH is used in case were we may build with and without nPth. The missing definition HAVE_NPTH didn't allowed us to build outher sources with nPTh support.
-rw-r--r--common/estream.c28
-rw-r--r--common/exechelp-posix.c2
-rw-r--r--common/exechelp-w32.c2
-rw-r--r--common/exechelp-w32ce.c2
-rw-r--r--common/http.c35
-rw-r--r--common/init.c8
-rw-r--r--common/sysutils.c14
-rw-r--r--configure.ac5
-rw-r--r--scd/ccid-driver.c14
9 files changed, 42 insertions, 68 deletions
diff --git a/common/estream.c b/common/estream.c
index 34726a3e4..3f924abd5 100644
--- a/common/estream.c
+++ b/common/estream.c
@@ -162,7 +162,7 @@ typedef void (*func_free_t) (void *mem);
/* Primitive system I/O. */
-#ifdef HAVE_NPTH
+#ifdef USE_NPTH
# define ESTREAM_SYS_READ do_npth_read
# define ESTREAM_SYS_WRITE do_npth_write
# define ESTREAM_SYS_YIELD() npth_usleep (0)
@@ -197,7 +197,7 @@ struct estream_internal
unsigned char buffer[BUFFER_BLOCK_SIZE];
unsigned char unread_buffer[BUFFER_UNREAD_SIZE];
-#ifdef HAVE_NPTH
+#ifdef USE_NPTH
npth_mutex_t lock; /* Lock. */
#endif
@@ -242,7 +242,7 @@ static int custom_std_fds[3];
static unsigned char custom_std_fds_valid[3];
/* A lock object for the estream list and the custom_std_fds array. */
-#ifdef HAVE_NPTH
+#ifdef USE_NPTH
static npth_mutex_t estream_list_lock;
#endif
@@ -358,7 +358,7 @@ map_w32_to_errno (DWORD w32_err)
static int
init_stream_lock (estream_t ES__RESTRICT stream)
{
-#ifdef HAVE_NPTH
+#ifdef USE_NPTH
int rc;
if (!stream->intern->samethread)
@@ -380,7 +380,7 @@ init_stream_lock (estream_t ES__RESTRICT stream)
static void
lock_stream (estream_t ES__RESTRICT stream)
{
-#ifdef HAVE_NPTH
+#ifdef USE_NPTH
if (!stream->intern->samethread)
{
dbg_lock_1 ("enter lock_stream for %p\n", stream);
@@ -396,7 +396,7 @@ lock_stream (estream_t ES__RESTRICT stream)
static int
trylock_stream (estream_t ES__RESTRICT stream)
{
-#ifdef HAVE_NPTH
+#ifdef USE_NPTH
int rc;
if (!stream->intern->samethread)
@@ -418,7 +418,7 @@ trylock_stream (estream_t ES__RESTRICT stream)
static void
unlock_stream (estream_t ES__RESTRICT stream)
{
-#ifdef HAVE_NPTH
+#ifdef USE_NPTH
if (!stream->intern->samethread)
{
dbg_lock_1 ("enter unlock_stream for %p\n", stream);
@@ -434,7 +434,7 @@ unlock_stream (estream_t ES__RESTRICT stream)
static int
init_list_lock (void)
{
-#ifdef HAVE_NPTH
+#ifdef USE_NPTH
int rc;
dbg_lock_0 ("enter init_list_lock\n");
@@ -450,7 +450,7 @@ init_list_lock (void)
static void
lock_list (void)
{
-#ifdef HAVE_NPTH
+#ifdef USE_NPTH
dbg_lock_0 ("enter lock_list\n");
npth_mutex_lock (&estream_list_lock);
dbg_lock_0 ("leave lock_list\n");
@@ -461,7 +461,7 @@ lock_list (void)
static void
unlock_list (void)
{
-#ifdef HAVE_NPTH
+#ifdef USE_NPTH
dbg_lock_0 ("enter unlock_list\n");
npth_mutex_unlock (&estream_list_lock);
dbg_lock_0 ("leave unlock_list\n");
@@ -548,7 +548,7 @@ do_list_remove (estream_t stream, int with_locked_list)
* write, assuming that we do I/O on a plain file where the operation
* can't block. FIXME: Is this still needed for npth?
*/
-#ifdef HAVE_NPTH
+#ifdef USE_NPTH
static int
do_npth_read (int fd, void *buffer, size_t size)
{
@@ -574,7 +574,7 @@ do_npth_write (int fd, const void *buffer, size_t size)
return npth_write (fd, buffer, size);
# endif /* !HAVE_W32_SYSTEM*/
}
-#endif /*HAVE_NPTH*/
+#endif /*USE_NPTH*/
@@ -1125,7 +1125,7 @@ es_func_w32_read (void *cookie, void *buffer, size_t size)
{
do
{
-#ifdef HAVE_NPTH
+#ifdef USE_NPTH
/* Note: Our pth_read actually uses HANDLE!
FIXME: Check whether this is the case for npth. */
bytes_read = npth_read ((int)w32_cookie->hd, buffer, size);
@@ -1171,7 +1171,7 @@ es_func_w32_write (void *cookie, const void *buffer, size_t size)
{
do
{
-#ifdef HAVE_NPTH
+#ifdef USE_NPTH
/* Note: Our pth_write actually uses HANDLE! */
bytes_written = npth_write ((int)w32_cookie->hd, buffer, size);
#else
diff --git a/common/exechelp-posix.c b/common/exechelp-posix.c
index 1290cfd39..249d38d09 100644
--- a/common/exechelp-posix.c
+++ b/common/exechelp-posix.c
@@ -50,7 +50,7 @@
#undef USE_NPTH
#endif
-#ifdef USE_NPTH
+#ifdef HAVE_NPTH
#include <npth.h>
#endif
#include <sys/wait.h>
diff --git a/common/exechelp-w32.c b/common/exechelp-w32.c
index 61193ed48..7bcd79bed 100644
--- a/common/exechelp-w32.c
+++ b/common/exechelp-w32.c
@@ -50,7 +50,7 @@
#undef USE_NPTH
#endif
-#ifdef USE_NPTH
+#ifdef HAVE_NPTH
#include <npth.h>
#endif
diff --git a/common/exechelp-w32ce.c b/common/exechelp-w32ce.c
index 886d51759..cca55c8ce 100644
--- a/common/exechelp-w32ce.c
+++ b/common/exechelp-w32ce.c
@@ -50,7 +50,7 @@
#undef USE_NPTH
#endif
-#ifdef USE_NPTH
+#ifdef HAVE_NPTH
#include <npth.h>
#endif
diff --git a/common/http.c b/common/http.c
index 541014153..11a713022 100644
--- a/common/http.c
+++ b/common/http.c
@@ -74,15 +74,13 @@
#endif /*!HAVE_W32_SYSTEM*/
#ifdef WITHOUT_NPTH /* Give the Makefile a chance to build without Pth. */
-# undef HAVE_NPTH
# undef USE_NPTH
#endif
-#ifdef HAVE_NPTH
+#ifdef USE_NPTH
# include <npth.h>
#endif
-
#ifdef HTTP_USE_GNUTLS
# include <gnutls/gnutls.h>
/* For non-understandable reasons GNUTLS dropped the _t suffix from
@@ -94,7 +92,7 @@ typedef gnutls_transport_ptr gnutls_transport_ptr_t;
#endif /*HTTP_USE_GNUTLS*/
#ifdef TEST
-#undef USE_DNS_SRV
+# undef USE_DNS_SRV
#endif
#include "util.h"
@@ -119,10 +117,10 @@ struct srventry
#endif/*!USE_DNS_SRV*/
-#ifdef HAVE_NPTH
-# define my_select(a,b,c,d,e) pth_select ((a), (b), (c), (d), (e))
-# define my_connect(a,b,c) pth_connect ((a), (b), (c))
-# define my_accept(a,b,c) pth_accept ((a), (b), (c))
+#ifdef USE_NPTH
+# define my_select(a,b,c,d,e) npth_select ((a), (b), (c), (d), (e))
+# define my_connect(a,b,c) npth_connect ((a), (b), (c))
+# define my_accept(a,b,c) npth_accept ((a), (b), (c))
#else
# define my_select(a,b,c,d,e) select ((a), (b), (c), (d), (e))
# define my_connect(a,b,c) connect ((a), (b), (c))
@@ -359,8 +357,9 @@ my_socket_unref (my_socket_t so)
/* #define my_socket_unref(a) _my_socket_unref ((a),__LINE__) */
+
/* This notification function is called by estream whenever stream is
- closed. Its purpose is to mark the the closing in the handle so
+ closed. Its purpose is to mark the closing in the handle so
that a http_close won't accidentally close the estream. The function
http_close removes this notification so that it won't be called if
http_close was used before an es_fclose. */
@@ -1835,7 +1834,7 @@ connect_server (const char *server, unsigned short port,
sock = socket (host->h_addrtype, SOCK_STREAM, 0);
if (sock == -1)
{
- log_error (_("error creating socket: %s\n"), strerror (errno));
+ log_error ("error creating socket: %s\n", strerror (errno));
xfree (serverlist);
return -1;
}
@@ -1879,7 +1878,7 @@ connect_server (const char *server, unsigned short port,
#ifdef HAVE_W32_SYSTEM
log_error ("can't connect to '%s': %s%sec=%d\n",
server,
- hostfound? "":_("host not found"),
+ hostfound? "":"host not found",
hostfound? "":" - ", (int)WSAGetLastError());
#else
log_error ("can't connect to '%s': %s\n",
@@ -1906,16 +1905,16 @@ write_server (int sock, const char *data, size_t length)
nleft = length;
while (nleft > 0)
{
-#if defined(HAVE_W32_SYSTEM) && !defined(HAVE_NPTH)
+#if defined(HAVE_W32_SYSTEM) && !defined(USE_NPTH)
nwritten = send (sock, data, nleft, 0);
if ( nwritten == SOCKET_ERROR )
{
log_info ("network write failed: ec=%d\n", (int)WSAGetLastError ());
return gpg_error (GPG_ERR_NETWORK);
}
-#else /*!HAVE_W32_SYSTEM || HAVE_NPTH*/
-# ifdef HAVE_NPTH
- nwritten = pth_write (sock, data, nleft);
+#else /*!HAVE_W32_SYSTEM || USE_NPTH*/
+# ifdef USE_NPTH
+ nwritten = npth_write (sock, data, nleft);
# else
nwritten = write (sock, data, nleft);
# endif
@@ -1935,7 +1934,7 @@ write_server (int sock, const char *data, size_t length)
log_info ("network write failed: %s\n", strerror (errno));
return gpg_error_from_syserror ();
}
-#endif /*!HAVE_W32_SYSTEM || HAVE_NPTH*/
+#endif /*!HAVE_W32_SYSTEM || USE_NPTH*/
nleft -= nwritten;
data += nwritten;
}
@@ -1990,8 +1989,8 @@ cookie_read (void *cookie, void *buffer, size_t size)
{
do
{
-#ifdef HAVE_NPTH
- nread = pth_read (c->sock->fd, buffer, size);
+#ifdef USE_NPTH
+ nread = npth_read (c->sock->fd, buffer, size);
#elif defined(HAVE_W32_SYSTEM)
/* Under Windows we need to use recv for a socket. */
nread = recv (c->sock->fd, buffer, size, 0);
diff --git a/common/init.c b/common/init.c
index 35e623fc2..91ee912bb 100644
--- a/common/init.c
+++ b/common/init.c
@@ -156,18 +156,12 @@ _init_common_subsystems (gpg_err_source_t errsource, int *argcp, char ***argvp)
#ifdef HAVE_W32_SYSTEM
/* For W32 we need to initialize the socket layer. This is because
we use recv and send in libassuan as well as at some other
- places. If we are building with PTH we let pth_init do it. We
- can't do much on error so we ignore them. An error would anyway
- later pop up if one of the socket functions is used. */
-# ifdef HAVE_NPTH
- pth_init ();
-# else
+ places. */
{
WSADATA wsadat;
WSAStartup (0x202, &wsadat);
}
-# endif /*!HAVE_NPTH*/
#endif
#ifdef HAVE_W32CE_SYSTEM
diff --git a/common/sysutils.c b/common/sysutils.c
index 95e0f8c0b..afb12edfd 100644
--- a/common/sysutils.c
+++ b/common/sysutils.c
@@ -275,18 +275,8 @@ check_permissions(const char *path,int extension,int checkonly)
void
gnupg_sleep (unsigned int seconds)
{
-#ifdef HAVE_NPTH
- /* With Pth we force a regular sleep for seconds == 0 so that also
- the process will give up its timeslot. */
- if (!seconds)
- {
-# ifdef HAVE_W32_SYSTEM
- Sleep (0);
-# else
- sleep (0);
-# endif
- }
- pth_sleep (seconds);
+#ifdef USE_NPTH
+ npth_sleep (seconds);
#else
/* Fixme: make sure that a sleep won't wake up to early. */
# ifdef HAVE_W32_SYSTEM
diff --git a/configure.ac b/configure.ac
index 096e3e170..19c98162d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -900,9 +900,10 @@ AC_DEFINE_UNQUOTED(SHRED,
#
AM_PATH_NPTH("$NEED_NPTH_API:$NEED_NPTH_VERSION",have_npth=yes,have_npth=no)
if test "$have_npth" = "yes"; then
- # We define this macro because some code parts require it.
- AC_DEFINE(USE_NPTH, 1,
+ AC_DEFINE(HAVE_NPTH, 1,
[Defined if the New Portable Thread Library is available])
+ AC_DEFINE(USE_NPTH, 1,
+ [Defined if support for nPth is requested and nPth is available])
else
AC_MSG_WARN([[
***
diff --git a/scd/ccid-driver.c b/scd/ccid-driver.c
index 0ac5aaf90..60ac5766b 100644
--- a/scd/ccid-driver.c
+++ b/scd/ccid-driver.c
@@ -315,18 +315,8 @@ set_msg_len (unsigned char *msg, unsigned int length)
static void
my_sleep (int seconds)
{
-#ifdef HAVE_NPTH
- /* With Pth we also call the standard sleep(0) so that the process
- may give up its timeslot. */
- if (!seconds)
- {
-# ifdef HAVE_W32_SYSTEM
- Sleep (0);
-# else
- sleep (0);
-# endif
- }
- pth_sleep (seconds);
+#ifdef USE_NPTH
+ npth_sleep (seconds);
#else
# ifdef HAVE_W32_SYSTEM
Sleep (seconds*1000);