[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r3048 - in GNUnet/src/util: . config_impl loggers network
From: |
grothoff |
Subject: |
[GNUnet-SVN] r3048 - in GNUnet/src/util: . config_impl loggers network |
Date: |
Sat, 24 Jun 2006 20:07:22 -0700 (PDT) |
Author: grothoff
Date: 2006-06-24 20:07:19 -0700 (Sat, 24 Jun 2006)
New Revision: 3048
Modified:
GNUnet/src/util/config_impl/impl.c
GNUnet/src/util/initialize.c
GNUnet/src/util/loggers/file.c
GNUnet/src/util/loggers/memory.c
GNUnet/src/util/network/tcpio.c
GNUnet/src/util/time.c
Log:
towards compiling util
Modified: GNUnet/src/util/config_impl/impl.c
===================================================================
--- GNUnet/src/util/config_impl/impl.c 2006-06-25 01:49:25 UTC (rev 3047)
+++ GNUnet/src/util/config_impl/impl.c 2006-06-25 03:07:19 UTC (rev 3048)
@@ -24,7 +24,7 @@
* @author Christian Grothoff
*/
-#include "gnunet_config_impl.h"
+#include "gnunet_util_config_impl.h"
#include "gnunet_util.h"
#include "platform.h"
@@ -94,7 +94,7 @@
/**
* Lock to access the data.
*/
- Mutex lock;
+ struct MUTEX * lock;
/**
* Context for logging errors, maybe NULL.
@@ -151,7 +151,7 @@
0);
GE_ASSERT(cfg->data->ectx,
cfg->data->listeners == 0);
- MUTEX_DESTROY(&cfg->data->lock);
+ MUTEX_DESTROY(cfg->data->lock);
FREE(cfg->data);
}
@@ -174,14 +174,14 @@
int ret;
char * section;
- MUTEX_LOCK(&cfg->data->lock);
+ MUTEX_LOCK(cfg->data->lock);
dirty = cfg->data->dirty; /* back up value! */
if (NULL == (fp = FOPEN(filename, "r"))) {
GE_LOG_STRERROR_FILE(cfg->data->ectx,
GE_ERROR | GE_USER | GE_IMMEDIATE | GE_BULK |
GE_REQUEST,
"fopen",
filename);
- MUTEX_UNLOCK(&cfg->data->lock);
+ MUTEX_UNLOCK(cfg->data->lock);
return -1;
}
ret = 0;
@@ -209,7 +209,8 @@
line[i] = '\0';
if (1 == sscanf(line, "@INLINE@ %191[^\n]", value) ) {
/* @INLINE@ value */
- char * expanded = expandFileName(value);
+ char * expanded = string_expandFileName(cfg->data->ectx,
+ value);
if (0 != _parse_configuration(cfg,
expanded))
ret = -1; /* failed to parse included config */
@@ -266,7 +267,7 @@
/* restore dirty flag - anything we set in the meantime
came from disk */
cfg->data->dirty = dirty;
- MUTEX_UNLOCK(&cfg->data->lock);
+ MUTEX_UNLOCK(cfg->data->lock);
FREE(section);
return ret;
}
@@ -295,7 +296,7 @@
data = cfg->data;
error = 0;
ret = 0;
- MUTEX_LOCK(&data->lock);
+ MUTEX_LOCK(data->lock);
for (i=0;i<data->ssize;i++) {
sec = &data->sections[i];
if (0 > fprintf(fp,
@@ -342,7 +343,7 @@
ret = -1;
data->dirty = -1; /* last write failed */
}
- MUTEX_UNLOCK(&data->lock);
+ MUTEX_UNLOCK(data->lock);
return ret;
}
@@ -392,7 +393,7 @@
const char * val;
int ret;
- MUTEX_LOCK(&cfg->data->lock);
+ MUTEX_LOCK(cfg->data->lock);
e = findEntry(cfg->data,
section,
option);
@@ -432,7 +433,7 @@
*number = def;
ret = 1; /* default */
}
- MUTEX_UNLOCK(&cfg->data->lock);
+ MUTEX_UNLOCK(cfg->data->lock);
return ret;
}
@@ -446,7 +447,7 @@
const char * val;
int ret;
- MUTEX_LOCK(&cfg->data->lock);
+ MUTEX_LOCK(cfg->data->lock);
e = findEntry(cfg->data,
section,
option);
@@ -457,7 +458,7 @@
*value = STRDUP(def);
ret = 1; /* default */
}
- MUTEX_UNLOCK(&cfg->data->lock);
+ MUTEX_UNLOCK(cfg->data->lock);
return ret;
}
@@ -473,7 +474,7 @@
int i;
int ret;
- MUTEX_LOCK(&cfg->data->lock);
+ MUTEX_LOCK(cfg->data->lock);
e = findEntry(cfg->data,
section,
option);
@@ -503,7 +504,7 @@
*value = def;
ret = 1; /* default */
}
- MUTEX_UNLOCK(&cfg->data->lock);
+ MUTEX_UNLOCK(cfg->data->lock);
return ret;
}
@@ -522,7 +523,7 @@
int i;
data = cfg->data;
- MUTEX_LOCK(&data->lock);
+ MUTEX_LOCK(data->lock);
e = findEntry(data, section, option);
if (e == NULL) {
sec = findSection(data, section);
@@ -581,7 +582,7 @@
ret = 0;
}
}
- MUTEX_UNLOCK(&data->lock);
+ MUTEX_UNLOCK(data->lock);
return ret;
}
@@ -611,13 +612,13 @@
void * ctx) {
GC_Listener l;
- MUTEX_LOCK(&cfg->data->lock);
+ MUTEX_LOCK(cfg->data->lock);
l.listener = callback;
l.ctx = ctx;
APPEND(cfg->data->listeners,
cfg->data->lsize,
l);
- MUTEX_UNLOCK(&cfg->data->lock);
+ MUTEX_UNLOCK(cfg->data->lock);
return -1;
}
@@ -628,7 +629,7 @@
int i;
GC_Listener * l;
- MUTEX_LOCK(&cfg->data->lock);
+ MUTEX_LOCK(cfg->data->lock);
for (i=cfg->data->lsize-1;i>=0;i--) {
l = &cfg->data->listeners[i];
if ( (l->listener == callback) &&
@@ -638,11 +639,11 @@
GROW(cfg->data->listeners,
cfg->data->lsize,
cfg->data->lsize-1);
- MUTEX_UNLOCK(&cfg->data->lock);
+ MUTEX_UNLOCK(cfg->data->lock);
return 0;
}
}
- MUTEX_UNLOCK(&cfg->data->lock);
+ MUTEX_UNLOCK(cfg->data->lock);
return -1;
}
@@ -656,7 +657,7 @@
ret = MALLOC(sizeof(GC_Configuration));
ret->data = MALLOC(sizeof(GC_ConfigurationData));
memset(ret->data, 0, sizeof(GC_ConfigurationData));
- MUTEX_CREATE_RECURSIVE(&ret->data->lock);
+ ret->data->lock = MUTEX_CREATE(YES);
ret->free = &_free;
ret->set_error_context = &_set_error_context;
ret->parse_configuration = &_parse_configuration;
Modified: GNUnet/src/util/initialize.c
===================================================================
--- GNUnet/src/util/initialize.c 2006-06-25 01:49:25 UTC (rev 3047)
+++ GNUnet/src/util/initialize.c 2006-06-25 03:07:19 UTC (rev 3048)
@@ -27,52 +27,12 @@
#include "platform.h"
#include "gnunet_util.h"
-void initState();
-
/**
- * Clean shutdown of the state module
- */
-void doneState();
-
-/**
- * The following method is called in order to initialize the status
- * calls routines. After that it is safe to call each of the status
- * calls separately
- */
-void initStatusCalls();
-
-/**
- * Shutdown the module.
- */
-void doneStatusCalls();
-
-void gnunet_util_initIO();
-void gnunet_util_doneIO();
-
-/**
- * Initialize controlThread.
- */
-void initCron();
-
-/**
- * Make sure to call stopCron before calling this method!
- */
-void doneCron();
-
-/**
* Set our process priority
*/
-void setProcessPrio() {
- char *str;
+static void setProcessPrio(const char * str) {
int prio = 0;
- /* Get setting as string */
- str = getConfigurationString(testConfigurationString("GNUNETD",
- "_MAGIC_",
- "YES")
- ? "GNUNETD"
- : "GNUNET",
- "PROCESS-PRIORITY");
if (str) {
/* We support four levels (NORMAL, ABOVE NORMAL, BELOW NORMAL, HIGH and
IDLE)
* and the usual numeric nice() increments */
@@ -131,14 +91,13 @@
errno = 0;
nice(prio);
if (errno != 0)
- LOG_STRERROR(LOG_WARNING, "nice");
+ GE_LOG_STRERROR(NULL,
+ GE_WARNING | GE_ADMIN | GE_BULK,
+ "nice");
#endif
- FREE(str);
}
}
-static int initStatus;
-
/**
* Initialize the util library. Use argc, argv and the given parser
* for processing command-line options <strong>after</strong> the
@@ -146,8 +105,7 @@
* and other configuration-dependent features are started.
*/
int initUtil(int argc,
- char * argv[],
- CommandLineParser parser) {
+ char * argv[]) {
#ifdef MINGW
if (InitWinEnv() != ERROR_SUCCESS)
@@ -158,41 +116,18 @@
BINDTEXTDOMAIN("GNUnet", LOCALEDIR);
textdomain("GNUnet");
#endif
- gnunet_util_initIO();
- initConfiguration();
- if (argc > 0)
+ /* if (argc > 0)
setConfigurationString("MAIN",
"ARGV[0]",
- argv[0]);
- initCron();
- if (parser != NULL)
- if (SYSERR == parser(argc, argv))
- return SYSERR;
- readConfiguration();
- setProcessPrio();
- initLogging();
- initStatus = testConfigurationString("GNUNETD",
- "_MAGIC_",
- "YES");
- if (initStatus)
- initStatusCalls();
- initState();
+ argv[0]);*/
+ // setProcessPrio();
return OK;
}
void doneUtil() {
- if (initStatus) {
- doneStatusCalls();
- initStatus = 0;
- }
- doneCron();
- doneState();
- LOG(LOG_MESSAGE,
- _("Shutdown complete.\n"));
#ifdef MINGW
ShutdownWinEnv();
#endif
- gnunet_util_doneIO();
}
Modified: GNUnet/src/util/loggers/file.c
===================================================================
--- GNUnet/src/util/loggers/file.c 2006-06-25 01:49:25 UTC (rev 3047)
+++ GNUnet/src/util/loggers/file.c 2006-06-25 03:07:19 UTC (rev 3048)
@@ -59,7 +59,7 @@
/**
* Lock.
*/
- Mutex lock;
+ struct MUTEX * lock;
/**
* Should we log the current date with each message?
@@ -203,7 +203,7 @@
char * name;
int ret;
- MUTEX_LOCK(&fctx->lock);
+ MUTEX_LOCK(fctx->lock);
if (fctx->logrotate) {
name = getLogFileName(fctx->ectx,
fctx->basename);
@@ -213,9 +213,10 @@
fctx->handle = FOPEN(name, "w+");
FREE(fctx->filename);
fctx->filename = name;
- scanDirectory(fctx->basename,
- &removeOldLog,
- fctx);
+ disk_directory_scan(fctx->ectx,
+ fctx->basename,
+ &removeOldLog,
+ fctx);
} else {
FREE(name);
}
@@ -238,14 +239,14 @@
"fclose");
fflush(fctx->handle);
- MUTEX_UNLOCK(&fctx->lock);
+ MUTEX_UNLOCK(fctx->lock);
}
static void
fileclose(void * cls) {
FileContext * fctx = cls;
- MUTEX_DESTROY(&fctx->lock);
+ MUTEX_DESTROY(fctx->lock);
FREENONNULL(fctx->filename);
FREENONNULL(fctx->basename);
if ( (fctx->handle != stderr) &&
@@ -300,7 +301,7 @@
fctx->filename = STRDUP(filename);
fctx->basename = name;
fctx->logstart = start;
- MUTEX_CREATE_RECURSIVE(&fctx->lock);
+ fctx->lock = MUTEX_CREATE(YES);
return GE_create_context_callback(mask,
&filelogger,
fctx,
@@ -326,7 +327,7 @@
fctx->filename = NULL;
fctx->basename = NULL;
fctx->logstart = 0;
- MUTEX_CREATE_RECURSIVE(&fctx->lock);
+ fctx->lock = MUTEX_CREATE(YES);
return GE_create_context_callback(mask,
&filelogger,
fctx,
@@ -352,7 +353,7 @@
fctx->filename = NULL;
fctx->basename = NULL;
fctx->logstart = 0;
- MUTEX_CREATE_RECURSIVE(&fctx->lock);
+ fctx->lock = MUTEX_CREATE(YES);
return GE_create_context_callback(mask,
&filelogger,
fctx,
Modified: GNUnet/src/util/loggers/memory.c
===================================================================
--- GNUnet/src/util/loggers/memory.c 2006-06-25 01:49:25 UTC (rev 3047)
+++ GNUnet/src/util/loggers/memory.c 2006-06-25 03:07:19 UTC (rev 3048)
@@ -36,7 +36,7 @@
typedef struct GE_Memory {
GE_Message * messages;
- Mutex lock;
+ struct MUTEX * lock;
unsigned int maxSize;
unsigned int size;
unsigned int pos;
@@ -50,11 +50,11 @@
GE_Memory * ctx = cls;
unsigned int max;
- MUTEX_LOCK(&ctx->lock);
+ MUTEX_LOCK(ctx->lock);
if (ctx->pos == ctx->size) {
if ( (ctx->maxSize != 0) &&
(ctx->size == ctx->maxSize) ) {
- MUTEX_UNLOCK(&ctx->lock);
+ MUTEX_UNLOCK(ctx->lock);
return;
}
max = ctx->pos * 2 + 16;
@@ -74,7 +74,7 @@
ctx->messages[ctx->pos].mask = kind;
}
ctx->pos++;
- MUTEX_UNLOCK(&ctx->lock);
+ MUTEX_UNLOCK(ctx->lock);
}
/**
@@ -110,7 +110,7 @@
ret->size = 0;
ret->pos = 0;
ret->messages = NULL;
- MUTEX_CREATE(&ret->lock);
+ ret->lock = MUTEX_CREATE(NO);
return ret;
}
@@ -123,7 +123,7 @@
void * ctx) {
int i;
- MUTEX_LOCK(&memory->lock);
+ MUTEX_LOCK(memory->lock);
for (i=0;i<memory->pos;i++) {
handler(ctx,
memory->messages[i].mask,
@@ -133,13 +133,13 @@
FREE(memory->messages[i].msg);
}
memory->pos = 0;
- MUTEX_UNLOCK(&memory->lock);
+ MUTEX_UNLOCK(memory->lock);
}
void GE_free_memory(struct GE_Memory * memory) {
int i;
- MUTEX_DESTROY(&memory->lock);
+ MUTEX_DESTROY(memory->lock);
for (i=memory->pos-1;i>=0;i--) {
FREE(memory->messages[i].date);
FREE(memory->messages[i].msg);
Modified: GNUnet/src/util/network/tcpio.c
===================================================================
--- GNUnet/src/util/network/tcpio.c 2006-06-25 01:49:25 UTC (rev 3047)
+++ GNUnet/src/util/network/tcpio.c 2006-06-25 03:07:19 UTC (rev 3048)
@@ -40,6 +40,7 @@
#include "gnunet_util_network.h"
#include "gnunet_util_os.h"
#include "gnunet_util_config.h"
+#include "gnunet_protocols.h"
#include "platform.h"
#define DEBUG_TCPIO NO
@@ -50,19 +51,19 @@
* drops the connection, the client automatically tries
* to reconnect (and for that needs connection information).
*/
-typedef struct GNUNET_TCP_SOCKET {
+typedef struct ClientServerConnection {
/**
* the socket handle, NULL if not life
*/
- struct SocketHandle * socket;
+ struct SocketHandle * sock;
- struct Mutex * readlock;
+ struct MUTEX * readlock;
+
+ struct MUTEX * writelock;
- struct Mutex * writelock;
+ struct GE_Context * ectx;
- struct CE_Context * ectx;
-
struct GC_Configuration * cfg;
/**
@@ -75,73 +76,70 @@
*/
int isServerSocket;
-} GNUNET_TCP_SOCKET;
+} ClientServerConnection;
/**
* Return the port-number (in host byte order)
+ * @return 0 on error
*/
-static unsigned short getGNUnetPort() {
- // TODO!
- static unsigned short port;
- const char *setting;
+static unsigned short getGNUnetPort(struct GE_Context * ectx,
+ struct GC_Configuration * cfg) {
+ unsigned long long port;
- if (port != 0)
- return port;
- if (testConfigurationString("GNUNETD",
- "_MAGIC_",
- "YES"))
- setting = "PORT";
- else
- setting = "CLIENT-PORT";
-
- port = (unsigned short) getConfigurationInt("NETWORK",
- setting);
- if (port == 0) {
- errexit(_("Cannot determine port of gnunetd server. "
- "Define in configuration file in section `%s' under `%s'.\n"),
- "NETWORK",
- setting);
+ port = 2087;
+ if (-1 == GC_get_configuration_value_number(cfg,
+ "NETWORK",
+ "PORT",
+ 1,
+ 65535,
+ 2087,
+ &port)) {
+ GE_LOG(ectx,
+ GE_ERROR | GE_USER | GE_BULK,
+ _("Could not find valid value for PORT in section NETWORK."));
+ return 0;
}
- return port;
+ return (unsigned short) port;
}
/**
* Configuration: get the GNUnetd host where the client
* should connect to (via TCP)
- * @return the name of the host
+ *
+ * @return the name of the host, NULL on error
*/
-static const char * getGNUnetdHost() {
- // TODO!
- static char * res;
+static char * getGNUnetdHost(struct GE_Context * ectx,
+ struct GC_Configuration * cfg) {
+ char * res;
- if (res != NULL)
- return res;
- res = getConfigurationString("NETWORK",
- "HOST");
- if (res == NULL)
- res = "localhost";
+ res = NULL;
+ if (-1 == GC_get_configuration_value_string(cfg,
+ "NETWORK",
+ "HOST",
+ "localhost",
+ &res)) {
+ GE_LOG(ectx,
+ GE_ERROR | GE_USER | GE_BULK,
+ _("Could not find valid value for HOST in section NETWORK."));
+ return NULL;
+ }
return res;
}
-/**
- * Initialize a GNUnet server socket.
- * @param sock the open socket
- * @param result the SOCKET (filled in)
- * @return OK (always successful)
- */
struct ClientServerConnection *
client_connection_create(struct GE_Context * ectx,
struct GC_Configuration * cfg,
struct SocketHandle * sock) {
- // TODO!
- result->ip.addr = 0;
- result->port = 0;
- result->socket = sock;
- result->outBufLen = 0;
- result->outBufPending = NULL;
- MUTEX_CREATE(&result->readlock);
- MUTEX_CREATE(&result->writelock);
+ ClientServerConnection * result;
+
+ result = MALLOC(sizeof(ClientServerConnection));
+ result->sock = sock;
+ result->readlock = MUTEX_CREATE(NO);
+ result->writelock = MUTEX_CREATE(NO);
+ result->ectx = ectx;
+ result->cfg = cfg;
+ result->isServerSocket = YES;
return result;
}
@@ -152,148 +150,131 @@
struct ClientServerConnection *
daemon_connection_create(struct GE_Context * ectx,
struct GC_Configuration * cfg) {
- // TODO!
- struct ClientServerConnection * sock;
- const char * host;
+ ClientServerConnection * result;
- result->ip = ip;
- result->port = port;
- result->socket = -1; /* closed */
- result->outBufLen = 0;
- result->outBufPending = NULL;
- MUTEX_CREATE(&result->readlock);
- MUTEX_CREATE(&result->writelock);
-
- if (OK != GN_getHostByName(hostname,
- &result->ip))
- return SYSERR;
-
- sock = MALLOC(sizeof(struct ClientServerConnection));
- host = getGNUnetdHost();
- if (SYSERR == initGNUnetClientSocket(getGNUnetPort(),
- host,
- sock)) {
- LOG(LOG_ERROR,
- _("Could not connect to gnunetd.\n"));
- FREE(sock);
- return NULL;
- }
- return sock;
+ result = MALLOC(sizeof(ClientServerConnection));
+ result->sock = NULL;
+ result->readlock = MUTEX_CREATE(NO);
+ result->writelock = MUTEX_CREATE(NO);
+ result->ectx = ectx;
+ result->cfg = cfg;
+ result->isServerSocket = NO;
+ return result;
}
void connection_close_temporarily(struct ClientServerConnection * sock) {
- // TODO!
- int i;
- GE_ASSERT(NULL, sock != NULL);
- if (sock->socket != -1) {
- i = sock->socket;
-#if DEBUG_TCPIO
- LOG(LOG_DEBUG,
- "TCP: closing socket %d.\n",
- sock->socket);
-#endif
- sock->socket = -1;
- if (0 != SHUTDOWN(i, SHUT_RDWR))
- LOG_STRERROR(LOG_DEBUG, "shutdown");
- CLOSE(i);
+ if (sock->sock != NULL) {
+ socket_destroy(sock->sock);
+ sock->sock = NULL;
}
- sock->outBufLen = 0;
- FREENONNULL(sock->outBufPending);
- sock->outBufPending = NULL;
}
void connection_destroy(struct ClientServerConnection * sock) {
connection_close_temporarily(sock);
- sock->ip.addr = 0;
- sock->port = 0;
- sock->outBufLen = 0;
- FREENONNULL(sock->outBufPending);
- sock->outBufPending = NULL;
MUTEX_DESTROY(sock->readlock);
MUTEX_DESTROY(sock->writelock);
FREE(sock);
}
int connection_test_open(struct ClientServerConnection * sock) {
- return (sock->socket != -1);
+ return (sock->sock != NULL);
}
/**
* Check a socket, open and connect if it is closed and it is a client-socket.
*/
int connection_ensure_connected(struct ClientServerConnection * sock) {
- // TODO!
- int res;
struct sockaddr_in soaddr;
fd_set rset;
fd_set wset;
fd_set eset;
struct timeval timeout;
int ret;
- int wasSockBlocking;
+ int osock;
+ unsigned short port;
+ char * host;
+ IPaddr ip;
- if (sock->socket != -1)
+ if (sock->sock != NULL)
return OK;
- sock->socket = SOCKET(PF_INET, SOCK_STREAM, 6); /* 6: TCP */
- if (sock->socket == -1) {
- LOG_STRERROR(LOG_FAILURE, "socket");
+ port = getGNUnetPort(sock->ectx,
+ sock->cfg);
+ if (port == 0)
return SYSERR;
+ host = getGNUnetdHost(sock->ectx,
+ sock->cfg);
+ if (host == NULL)
+ return SYSERR;
+ if (SYSERR == get_host_by_name(sock->ectx,
+ host,
+ &ip)) {
+ FREE(host);
+ return SYSERR;
}
-
- wasSockBlocking = isSocketBlocking(sock->socket);
- setBlocking(sock->socket, NO);
-
+ osock = SOCKET(PF_INET, SOCK_STREAM, 6); /* 6: TCP */
+ if (osock == -1) {
+ GE_LOG_STRERROR(sock->ectx,
+ GE_ERROR | GE_USER | GE_ADMIN | GE_BULK,
+ "socket");
+ FREE(host);
+ return SYSERR;
+ }
+ sock->sock = socket_create(sock->ectx,
+ NULL,
+ osock);
+ socket_set_blocking(sock->sock, NO);
soaddr.sin_family = AF_INET;
- GNUNET_ASSERT(sizeof(struct in_addr) == sizeof(sock->ip.addr));
+ GE_ASSERT(sock->ectx,
+ sizeof(struct in_addr) == sizeof(IPaddr));
memcpy(&soaddr.sin_addr,
- &sock->ip.addr,
+ &ip,
sizeof(struct in_addr));
- soaddr.sin_port = htons(sock->port);
- res = CONNECT(sock->socket,
+ soaddr.sin_port = htons(port);
+ ret = CONNECT(osock,
(struct sockaddr*)&soaddr,
sizeof(soaddr));
- if ( (res < 0) &&
+ if ( (ret < 0) &&
(errno != EINPROGRESS) ) {
- LOG(LOG_INFO,
- _("Cannot connect to %u.%u.%u.%u:%u: %s\n"),
- PRIP(ntohl(*(int*)&sock->ip.addr)),
- sock->port,
- STRERROR(errno));
- closefile(sock->socket);
- sock->socket = -1;
+ GE_LOG(sock->ectx,
+ GE_WARNING | GE_USER | GE_BULK,
+ _("Cannot connect to %s:u: %s\n"),
+ host,
+ port,
+ STRERROR(errno));
+ socket_destroy(sock->sock);
+ FREE(host);
return SYSERR;
}
-
/* we call select() first with a timeout of 5s to
avoid blocking on a later write indefinitely;
- this is mostly needed for gnunet-testbed to keep
- working if an advertised testbed-client is behind
- a firewall and unreachable. But it is also nice
- if a local firewall decides to just drop the TCP
- handshake...*/
+ Important if a local firewall decides to just drop
+ the TCP handshake...*/
FD_ZERO(&rset);
FD_ZERO(&wset);
FD_ZERO(&eset);
- if (sock->socket < 0)
- return SYSERR;
- FD_SET(sock->socket, &wset);
+ FD_SET(osock, &wset);
timeout.tv_sec = 5;
timeout.tv_usec = 0;
- ret = SELECT(sock->socket+1, &rset, &wset, &eset, &timeout);
+ ret = SELECT(osock + 1,
+ &rset,
+ &wset,
+ &eset,
+ &timeout);
if ( (ret == -1) ||
- (sock->socket == -1) ||
- (! FD_ISSET(sock->socket,
+ (! FD_ISSET(osock,
&wset)) ) {
- LOG(LOG_INFO,
- _("Cannot connect to %u.%u.%u.%u:%u: %s\n"),
- PRIP(ntohl(*(int*)&sock->ip.addr)),
- sock->port,
- STRERROR(errno));
- setBlocking(sock->socket, wasSockBlocking);
+ GE_LOG(sock->ectx,
+ GE_WARNING | GE_USER | GE_BULK,
+ _("Cannot connect to %s:u: %s\n"),
+ host,
+ port,
+ STRERROR(errno));
+ socket_destroy(sock->sock);
+ FREE(host);
return SYSERR;
}
- setBlocking(sock->socket, wasSockBlocking);
-
+ FREE(host);
+ socket_set_blocking(sock->sock, YES);
return OK;
}
@@ -307,52 +288,26 @@
*/
int connection_write(struct ClientServerConnection * sock,
const MESSAGE_HEADER * buffer) {
- // TODO!
+ size_t size;
+ size_t sent;
int res;
- int size;
- if (SYSERR == checkSocket(sock))
+ if (SYSERR == connection_ensure_connected(sock))
return SYSERR;
size = ntohs(buffer->size);
- MUTEX_LOCK(&sock->writelock);
-
- /* write pending data from prior non-blocking call
- -- but this time use blocking IO! */
- if (sock->outBufLen > 0) {
- res = SEND_BLOCKING_ALL(sock->socket,
- sock->outBufPending,
- sock->outBufLen);
- if (res < 0) {
- if (errno == EAGAIN) {
- MUTEX_UNLOCK(&sock->writelock);
- return SYSERR; /* can not send right now;
- but do NOT close socket in this case! */
- }
- LOG_STRERROR(LOG_INFO, "send");
- closeSocketTemporarily(sock);
- MUTEX_UNLOCK(&sock->writelock);
- return SYSERR;
- }
- FREE(sock->outBufPending);
- sock->outBufPending = NULL;
- sock->outBufLen = 0;
- }
-
- res = SEND_BLOCKING_ALL(sock->socket,
- buffer,
- size);
- if (res < 0) {
- if (errno == EAGAIN) {
- MUTEX_UNLOCK(&sock->writelock);
- return SYSERR; /* would block, can not send right now;
- but do NOT close socket in this case! */
- }
- LOG_STRERROR(LOG_INFO, "send");
- closeSocketTemporarily(sock);
- MUTEX_UNLOCK(&sock->writelock);
+ MUTEX_LOCK(sock->writelock);
+ res = socket_send(sock->sock,
+ NC_Complete,
+ buffer,
+ size,
+ &sent);
+ if ( (res != YES) ||
+ (sent != size) ) {
+ connection_close_temporarily(sock);
+ MUTEX_UNLOCK(sock->writelock);
return SYSERR;
}
- MUTEX_UNLOCK(&sock->writelock);
+ MUTEX_UNLOCK(sock->writelock);
return OK;
}
@@ -369,7 +324,7 @@
MUTEX_LOCK(sock->readlock);
pos = 0;
res = 0;
- if ( (OK != socket_recv(sock->handle,
+ if ( (OK != socket_recv(sock->sock,
NC_Complete,
&size,
sizeof(unsigned short),
@@ -387,7 +342,7 @@
}
buf = MALLOC(size);
- if ( (OK != socket_recv(sock->handle,
+ if ( (OK != socket_recv(sock->sock,
NC_Complete,
&buf[pos],
size - pos,
@@ -395,7 +350,7 @@
(pos != sizeof(unsigned short) + size) ) {
connection_close_temporarily(sock);
FREE(buf);
- MUTEX_UNLOCK(&sock->readlock);
+ MUTEX_UNLOCK(sock->readlock);
return SYSERR;
}
#if DEBUG_TCPIO
@@ -403,7 +358,7 @@
"Successfully received %d bytes from TCP socket.\n",
size);
#endif
- MUTEX_UNLOCK(&sock->readlock);
+ MUTEX_UNLOCK(sock->readlock);
*buffer = (MESSAGE_HEADER*) buf;
(*buffer)->size = htons(size);
return OK; /* success */
@@ -471,14 +426,13 @@
RETURN_VALUE_MESSAGE rv;
rv.header.size
- = htons(sizeof(CS_returnvalue_MESSAGE));
+ = htons(sizeof(RETURN_VALUE_MESSAGE));
rv.header.type
= htons(CS_PROTO_RETURN_VALUE);
rv.return_value
= htonl(ret);
return connection_write(sock,
- &rv.header,
- YES);
+ &rv.header);
}
/**
Modified: GNUnet/src/util/time.c
===================================================================
--- GNUnet/src/util/time.c 2006-06-25 01:49:25 UTC (rev 3047)
+++ GNUnet/src/util/time.c 2006-06-25 03:07:19 UTC (rev 3048)
@@ -1,3 +1,7 @@
+
+#include "gnunet_util.h"
+#include "platform.h"
+
/**
* TIME prototype. "man time".
*/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r3048 - in GNUnet/src/util: . config_impl loggers network,
grothoff <=