Renamed the hub_sendq and hub_recvq to ioq_send and ioq_recv.

This commit is contained in:
Jan Vidar Krey 2012-09-28 09:20:33 +02:00
parent 35bfefa717
commit fc52f0e030
8 changed files with 58 additions and 59 deletions

View File

@ -142,8 +142,8 @@ libuhub_SOURCES := \
src/core/eventqueue.c \
src/core/hub.c \
src/core/hubevent.c \
src/core/hubio.c \
src/core/inf.c \
src/core/ioqueue.c \
src/core/netevent.c \
src/core/probe.c \
src/core/route.c \

View File

@ -1,6 +1,6 @@
/*
* uhub - A tiny ADC p2p connection hub
* Copyright (C) 2007-2010, Jan Vidar Krey
* Copyright (C) 2007-2012, Jan Vidar Krey
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -18,7 +18,6 @@
*/
#include "uhub.h"
#include "hubio.h"
#ifdef DEBUG_SENDQ
static void debug_msg(const char* prefix, struct adc_message* msg)
@ -35,13 +34,13 @@ static void debug_msg(const char* prefix, struct adc_message* msg)
}
#endif
struct hub_recvq* hub_recvq_create()
struct ioq_recv* ioq_recv_create()
{
struct hub_recvq* q = hub_malloc_zero(sizeof(struct hub_recvq));
struct ioq_recv* q = hub_malloc_zero(sizeof(struct ioq_recv));
return q;
}
void hub_recvq_destroy(struct hub_recvq* q)
void ioq_recv_destroy(struct ioq_recv* q)
{
if (q)
{
@ -50,7 +49,7 @@ void hub_recvq_destroy(struct hub_recvq* q)
}
}
size_t hub_recvq_get(struct hub_recvq* q, void* buf, size_t bufsize)
size_t ioq_recv_get(struct ioq_recv* q, void* buf, size_t bufsize)
{
uhub_assert(bufsize >= q->size);
if (q->size)
@ -65,7 +64,7 @@ size_t hub_recvq_get(struct hub_recvq* q, void* buf, size_t bufsize)
return 0;
}
size_t hub_recvq_set(struct hub_recvq* q, void* buf, size_t bufsize)
size_t ioq_recv_set(struct ioq_recv* q, void* buf, size_t bufsize)
{
if (q->buf)
{
@ -89,9 +88,9 @@ size_t hub_recvq_set(struct hub_recvq* q, void* buf, size_t bufsize)
}
struct hub_sendq* hub_sendq_create()
struct ioq_send* ioq_send_create()
{
struct hub_sendq* q = hub_malloc_zero(sizeof(struct hub_sendq));
struct ioq_send* q = hub_malloc_zero(sizeof(struct ioq_send));
if (!q)
return 0;
@ -110,7 +109,7 @@ static void clear_send_queue_callback(void* ptr)
adc_msg_free((struct adc_message*) ptr);
}
void hub_sendq_destroy(struct hub_sendq* q)
void ioq_send_destroy(struct ioq_send* q)
{
if (q)
{
@ -120,21 +119,21 @@ void hub_sendq_destroy(struct hub_sendq* q)
}
}
void hub_sendq_add(struct hub_sendq* q, struct adc_message* msg_)
void ioq_send_add(struct ioq_send* q, struct adc_message* msg_)
{
struct adc_message* msg = adc_msg_incref(msg_);
#ifdef DEBUG_SENDQ
debug_msg("hub_sendq_add", msg);
debug_msg("ioq_send_add", msg);
#endif
uhub_assert(msg->cache && *msg->cache);
list_append(q->queue, msg);
q->size += msg->length;
}
void hub_sendq_remove(struct hub_sendq* q, struct adc_message* msg)
void ioq_send_remove(struct ioq_send* q, struct adc_message* msg)
{
#ifdef DEBUG_SENDQ
debug_msg("hub_sendq_remove", msg);
debug_msg("ioq_send_remove", msg);
#endif
list_remove(q->queue, msg);
q->size -= msg->length;
@ -142,7 +141,7 @@ void hub_sendq_remove(struct hub_sendq* q, struct adc_message* msg)
q->offset = 0;
}
int hub_sendq_send(struct hub_sendq* q, struct hub_user* user)
int ioq_send_send(struct ioq_send* q, struct hub_user* user)
{
int ret;
struct adc_message* msg = list_get_first(q->queue);
@ -156,18 +155,18 @@ int hub_sendq_send(struct hub_sendq* q, struct hub_user* user)
if (msg->length - q->offset > 0)
return 0;
hub_sendq_remove(q, msg);
ioq_send_remove(q, msg);
return 1;
}
return ret;
}
int hub_sendq_is_empty(struct hub_sendq* q)
int ioq_send_is_empty(struct ioq_send* q)
{
return (q->size - q->offset) == 0;
}
size_t hub_sendq_get_bytes(struct hub_sendq* q)
size_t ioq_send_get_bytes(struct ioq_send* q)
{
return q->size - q->offset;
}

View File

@ -1,6 +1,6 @@
/*
* uhub - A tiny ADC p2p connection hub
* Copyright (C) 2007-2010, Jan Vidar Krey
* Copyright (C) 2007-2012, Jan Vidar Krey
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,25 +17,25 @@
*
*/
#ifndef HAVE_UHUB_HUB_IO_H
#define HAVE_UHUB_HUB_IO_H
#ifndef HAVE_UHUB_IO_QUEUE_H
#define HAVE_UHUB_IO_QUEUE_H
struct adc_message;
struct linked_list;
typedef int (*hub_recvq_write)(void* desc, const void* buf, size_t len);
typedef int (*hub_recvq_read)(void* desc, void* buf, size_t len);
typedef int (*ioq_write)(void* desc, const void* buf, size_t len);
typedef int (*ioq_read)(void* desc, void* buf, size_t len);
struct hub_sendq
struct ioq_send
{
size_t size; /** Size of send queue (in bytes, not messages) */
size_t offset; /** Queue byte offset in the first message. Should be 0 unless a partial write. */
#ifdef SSL_SUPPORT
size_t last_send; /** When using SSL, one have to send the exact same buffer and length if a write cannot complete. */
#endif
struct linked_list* queue; /** List of queued messages */
struct linked_list* queue; /** List of queued messages (struct adc_message) */
};
struct hub_recvq
struct ioq_recv
{
char* buf;
size_t size;
@ -44,63 +44,63 @@ struct hub_recvq
/**
* Create a send queue
*/
extern struct hub_sendq* hub_sendq_create();
extern struct ioq_send* ioq_send_create();
/**
* Destroy a send queue, and delete any queued messages.
*/
extern void hub_sendq_destroy(struct hub_sendq*);
extern void ioq_send_destroy(struct ioq_send*);
/**
* Add a message to the send queue.
*/
extern void hub_sendq_add(struct hub_sendq*, struct adc_message* msg);
extern void ioq_send_add(struct ioq_send*, struct adc_message* msg);
/**
* Process the send queue, and send as many messages as possible.
* @returns -1 on error, 0 if unable to send more, 1 if more can be sent.
*/
extern int hub_sendq_send(struct hub_sendq*, struct hub_user*);
extern int ioq_send_send(struct ioq_send*, struct hub_user*);
/**
* @returns 1 if send queue is empty, 0 otherwise.
*/
extern int hub_sendq_is_empty(struct hub_sendq*);
extern int ioq_send_is_empty(struct ioq_send*);
/**
* @returns the number of bytes remaining to be sent in the queue.
*/
extern size_t hub_sendq_get_bytes(struct hub_sendq*);
extern size_t ioq_send_get_bytes(struct ioq_send*);
/**
* Create a receive queue.
*/
extern struct hub_recvq* hub_recvq_create();
extern struct ioq_recv* ioq_recv_create();
/**
* Destroy a receive queue.
*/
extern void hub_recvq_destroy(struct hub_recvq*);
extern void ioq_recv_destroy(struct ioq_recv*);
/**
* Gets the buffer, copies it into buf and deallocates it.
* NOTE: bufsize *MUST* be larger than the buffer, otherwise it asserts.
* @return the number of bytes copied into buf.
*/
extern size_t hub_recvq_get(struct hub_recvq*, void* buf, size_t bufsize);
extern size_t ioq_recv_get(struct ioq_recv*, void* buf, size_t bufsize);
/**
* Sets the buffer
*/
extern size_t hub_recvq_set(struct hub_recvq*, void* buf, size_t bufsize);
extern size_t ioq_recv_set(struct ioq_recv*, void* buf, size_t bufsize);
/**
* @return 1 if size is zero, 0 otherwise.
*/
extern int hub_recvq_is_empty(struct hub_recvq* buf);
extern int ioq_recv_is_empty(struct ioq_recv* buf);
#endif /* HAVE_UHUB_HUB_IO_H */
#endif /* HAVE_UHUB_IO_QUEUE_H */

View File

@ -18,14 +18,14 @@
*/
#include <uhub.h>
#include "hubio.h"
#include "ioqueue.h"
#include "probe.h"
int handle_net_read(struct hub_user* user)
{
static char buf[MAX_RECV_BUF];
struct hub_recvq* q = user->recv_queue;
size_t buf_size = hub_recvq_get(q, buf, MAX_RECV_BUF);
struct ioq_recv* q = user->recv_queue;
size_t buf_size = ioq_recv_get(q, buf, MAX_RECV_BUF);
ssize_t size;
if (user_flag_get(user, flag_maxbuf))
@ -87,18 +87,18 @@ int handle_net_read(struct hub_user* user)
{
if (remaining < (size_t) user->hub->config->max_recv_buffer)
{
hub_recvq_set(q, lastPos ? lastPos : buf, remaining);
ioq_recv_set(q, lastPos ? lastPos : buf, remaining);
}
else
{
hub_recvq_set(q, 0, 0);
ioq_recv_set(q, 0, 0);
user_flag_set(user, flag_maxbuf);
LOG_WARN("Received message past max_recv_buffer, dropping message.");
}
}
else
{
hub_recvq_set(q, 0, 0);
ioq_recv_set(q, 0, 0);
}
}
return 0;
@ -107,9 +107,9 @@ int handle_net_read(struct hub_user* user)
int handle_net_write(struct hub_user* user)
{
int ret = 0;
while (hub_sendq_get_bytes(user->send_queue))
while (ioq_send_get_bytes(user->send_queue))
{
ret = hub_sendq_send(user->send_queue, user);
ret = ioq_send_send(user->send_queue, user);
if (ret <= 0)
break;
}
@ -117,7 +117,7 @@ int handle_net_write(struct hub_user* user)
if (ret < 0)
return quit_socket_error;
if (hub_sendq_get_bytes(user->send_queue))
if (ioq_send_get_bytes(user->send_queue))
{
user_net_io_want_write(user);
}

View File

@ -108,17 +108,17 @@ int route_to_user(struct hub_info* hub, struct hub_user* user, struct adc_messag
uhub_assert(msg->cache && *msg->cache);
if (hub_sendq_is_empty(user->send_queue) && !user_flag_get(user, flag_pipeline))
if (ioq_send_is_empty(user->send_queue) && !user_flag_get(user, flag_pipeline))
{
/* Perform oportunistic write */
hub_sendq_add(user->send_queue, msg);
ioq_send_add(user->send_queue, msg);
handle_net_write(user);
}
else
{
if (check_send_queue(hub, user, msg) >= 0)
{
hub_sendq_add(user->send_queue, msg);
ioq_send_add(user->send_queue, msg);
if (!user_flag_get(user, flag_pipeline))
user_net_io_want_write(user);
}
@ -128,7 +128,7 @@ int route_to_user(struct hub_info* hub, struct hub_user* user, struct adc_messag
int route_flush_pipeline(struct hub_info* hub, struct hub_user* u)
{
if (hub_sendq_is_empty(u->send_queue))
if (ioq_send_is_empty(u->send_queue))
return 0;
handle_net_write(u);

View File

@ -46,8 +46,8 @@ struct hub_user* user_create(struct hub_info* hub, struct net_connection* con, s
if (user == NULL)
return NULL; /* OOM */
user->send_queue = hub_sendq_create();
user->recv_queue = hub_recvq_create();
user->send_queue = ioq_send_create();
user->recv_queue = ioq_recv_create();
user->connection = con;
net_con_reinitialize(user->connection, net_event, user, NET_EVENT_READ);
@ -70,8 +70,8 @@ void user_destroy(struct hub_user* user)
{
LOG_TRACE("user_destroy(), user=%p", user);
hub_recvq_destroy(user->recv_queue);
hub_sendq_destroy(user->send_queue);
ioq_recv_destroy(user->recv_queue);
ioq_send_destroy(user->send_queue);
if (user->connection)
{

View File

@ -113,8 +113,8 @@ struct hub_user
struct linked_list* feature_cast; /** Features supported by feature cast */
struct adc_message* info; /** ADC 'INF' message (broadcasted to everyone joining the hub) */
struct hub_info* hub; /** The hub instance this user belong to */
struct hub_recvq* recv_queue;
struct hub_sendq* send_queue;
struct ioq_recv* recv_queue;
struct ioq_send* send_queue;
struct net_connection* connection; /** Connection data */
struct hub_user_limits limits; /** Data used for limitation */
enum user_quit_reason quit_reason; /** Quit reason (see user_quit_reason) */

View File

@ -82,7 +82,7 @@ extern "C" {
#include "core/eventid.h"
#include "core/eventqueue.h"
#include "core/netevent.h"
#include "core/hubio.h"
#include "core/ioqueue.h"
#include "core/user.h"
#include "core/usermanager.h"
#include "core/route.h"