* @param ptr pointer to user context
* @param size number of bytes in user context struct (for verification only)
*/
-void
+void
GNUNET_SERVER_client_set_user_context_ (struct GNUNET_SERVER_Client *client,
void *ptr,
size_t size)
* @param tc reason why we are running right now
*/
static void
-process_listen_socket (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+process_listen_socket (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_SERVER_Handle *server = cls;
struct GNUNET_CONNECTION_Handle *sock;
server->listen_sockets[i]);
if (NULL != sock)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Server accepted incoming connection.\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Server accepted incoming connection.\n");
client = GNUNET_SERVER_connect_socket (server, sock);
/* decrement reference count, we don't keep "client" alive */
GNUNET_SERVER_client_drop (client);
/**
* Create and initialize a listen socket for the server.
*
- * @param serverAddr address to listen on
- * @param socklen length of address
+ * @param server_addr address to listen on
+ * @param socklen length of @a server_addr
* @return NULL on error, otherwise the listen socket
*/
static struct GNUNET_NETWORK_Handle *
-open_listen_socket (const struct sockaddr *serverAddr, socklen_t socklen)
+open_listen_socket (const struct sockaddr *server_addr, socklen_t socklen)
{
struct GNUNET_NETWORK_Handle *sock;
uint16_t port;
int eno;
- switch (serverAddr->sa_family)
+ switch (server_addr->sa_family)
{
case AF_INET:
- port = ntohs (((const struct sockaddr_in *) serverAddr)->sin_port);
+ port = ntohs (((const struct sockaddr_in *) server_addr)->sin_port);
break;
case AF_INET6:
- port = ntohs (((const struct sockaddr_in6 *) serverAddr)->sin6_port);
+ port = ntohs (((const struct sockaddr_in6 *) server_addr)->sin6_port);
break;
case AF_UNIX:
port = 0;
port = 0;
break;
}
- sock = GNUNET_NETWORK_socket_create (serverAddr->sa_family, SOCK_STREAM, 0);
+ sock = GNUNET_NETWORK_socket_create (server_addr->sa_family, SOCK_STREAM, 0);
if (NULL == sock)
{
LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket");
return NULL;
}
/* bind the socket */
- if (GNUNET_OK != GNUNET_NETWORK_socket_bind (sock, serverAddr, socklen, 0))
+ if (GNUNET_OK != GNUNET_NETWORK_socket_bind (sock, server_addr, socklen))
{
eno = errno;
if (EADDRINUSE != errno)
if (0 != port)
LOG (GNUNET_ERROR_TYPE_ERROR, _("`%s' failed for port %d (%s).\n"),
"bind", port,
- (AF_INET == serverAddr->sa_family) ? "IPv4" : "IPv6");
+ (AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6");
eno = 0;
}
else
LOG (GNUNET_ERROR_TYPE_WARNING,
_("`%s' failed for port %d (%s): address already in use\n"),
"bind", port,
- (AF_INET == serverAddr->sa_family) ? "IPv4" : "IPv6");
- else if (AF_UNIX == serverAddr->sa_family)
+ (AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6");
+ else if (AF_UNIX == server_addr->sa_family)
{
- const struct sockaddr_un *un = (const struct sockaddr_un *) serverAddr;
- unsigned int off = 0;
-
- if ('\0' == un->sun_path[0])
- off = 1; /* some UNIXPATHs start with 0 */
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("`%s' failed for `%.*s': address already in use\n"), "bind",
- (int) ((sizeof (un->sun_path) - off)),
- (&un->sun_path[off]));
+ _("`%s' failed for `%s': address already in use\n"),
+ "bind",
+ GNUNET_a2s (server_addr, socklen));
}
}
GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
* @param access_cls closure for access
* @param lsocks NULL-terminated array of listen sockets
* @param idle_timeout after how long should we timeout idle connections?
- * @param require_found if YES, connections sending messages of unknown type
+ * @param require_found if #GNUNET_YES, connections sending messages of unknown type
* will be closed
* @return handle for the new server, NULL on error
* (typically, "port" already in use)
{
struct GNUNET_SERVER_Handle *server;
- server = GNUNET_malloc (sizeof (struct GNUNET_SERVER_Handle));
+ server = GNUNET_new (struct GNUNET_SERVER_Handle);
server->idle_timeout = idle_timeout;
server->listen_sockets = lsocks;
server->access = access;
*
* @param access function for access control
* @param access_cls closure for access
- * @param serverAddr address to listen on (including port), NULL terminated array
- * @param socklen length of serverAddr
+ * @param server_addr address to listen on (including port), NULL terminated array
+ * @param socklen length of server_addr
* @param idle_timeout after how long should we timeout idle connections?
* @param require_found if YES, connections sending messages of unknown type
* will be closed
*/
struct GNUNET_SERVER_Handle *
GNUNET_SERVER_create (GNUNET_CONNECTION_AccessCheck access, void *access_cls,
- struct sockaddr *const *serverAddr,
+ struct sockaddr *const *server_addr,
const socklen_t * socklen,
struct GNUNET_TIME_Relative idle_timeout,
int require_found)
int seen;
i = 0;
- while (NULL != serverAddr[i])
+ while (NULL != server_addr[i])
i++;
if (i > 0)
{
lsocks = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (i + 1));
i = 0;
j = 0;
- while (NULL != serverAddr[i])
+ while (NULL != server_addr[i])
{
seen = 0;
for (k=0;k<i;k++)
if ( (socklen[k] == socklen[i]) &&
- (0 == memcmp (serverAddr[k], serverAddr[i], socklen[i])) )
+ (0 == memcmp (server_addr[k], server_addr[i], socklen[i])) )
{
seen = 1;
break;
i++;
continue;
}
- lsocks[j] = open_listen_socket (serverAddr[i], socklen[i]);
+ lsocks[j] = open_listen_socket (server_addr[i], socklen[i]);
if (NULL != lsocks[j])
j++;
i++;
{
struct HandlerList *p;
- p = GNUNET_malloc (sizeof (struct HandlerList));
+ p = GNUNET_new (struct HandlerList);
p->handlers = handlers;
p->next = server->handlers;
server->handlers = p;
(GNUNET_SCHEDULER_NO_TASK == sender->warn_task) )
{
GNUNET_break (0 != type); /* type should never be 0 here, as we don't use 0 */
- sender->warn_start = GNUNET_TIME_absolute_get ();
+ sender->warn_start = GNUNET_TIME_absolute_get ();
sender->warn_task =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
&warn_no_receive_done, sender);
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Server leaves instant processing loop: ret = %d, server = %p, shutdown = %d, suspended = %u\n",
- ret, client->server,
+ ret, client->server,
client->shutdown_now,
client->suspended);
if (GNUNET_NO == ret)
struct GNUNET_SERVER_Client *client;
struct NotifyList *n;
- client = GNUNET_malloc (sizeof (struct GNUNET_SERVER_Client));
+ client = GNUNET_new (struct GNUNET_SERVER_Client);
client->connection = connection;
client->reference_count = 1;
client->server = server;
*/
void
GNUNET_SERVER_connect_notify (struct GNUNET_SERVER_Handle *server,
- GNUNET_SERVER_ConnectCallback callback,
+ GNUNET_SERVER_ConnectCallback callback,
void *callback_cls)
{
struct NotifyList *n;
*/
void
GNUNET_SERVER_connect_notify_cancel (struct GNUNET_SERVER_Handle *server,
- GNUNET_SERVER_ConnectCallback callback,
+ GNUNET_SERVER_ConnectCallback callback,
void *callback_cls)
{
struct NotifyList *pos;
const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_CONNECTION_Handle *connection = cls;
-
+
GNUNET_CONNECTION_destroy (connection);
}
GNUNET_CONNECTION_receive_cancel (client->connection);
client->receive_pending = GNUNET_NO;
}
- client->shutdown_now = GNUNET_YES;
+ client->shutdown_now = GNUNET_YES;
client->reference_count++; /* make sure nobody else clean up client... */
if ( (NULL != client->mst) &&
(NULL != server) )
* serious error)
*/
void
-GNUNET_SERVER_receive_done (struct GNUNET_SERVER_Client *client,
+GNUNET_SERVER_receive_done (struct GNUNET_SERVER_Client *client,
int success)
{
if (NULL == client)