Oportunistic write.

This commit is contained in:
Jan Vidar Krey 2009-06-22 20:25:22 +02:00
parent 1d9acece34
commit 1c58120c03
3 changed files with 15 additions and 9 deletions

View File

@ -240,14 +240,11 @@ void net_on_read(int fd, short ev, void *arg)
void net_on_write(int fd, short ev, void *arg)
{
struct user* user = (struct user*) arg;
int sent = 0;
for (;;)
{
int ret = hub_sendq_send(user->net.send_queue, net_user_send, user);
if (ret > 0)
sent += ret;
else
if (ret <= 0)
break;
}

View File

@ -59,7 +59,7 @@ int route_message(struct hub_info* hub, struct user* u, struct adc_message* msg)
}
// #define ALWAYS_QUEUE_MESSAGES
#if 0
static size_t get_max_send_queue(struct hub_info* hub)
{
/* TODO: More dynamic send queue limit, for instance:
@ -68,7 +68,6 @@ static size_t get_max_send_queue(struct hub_info* hub)
return hub->config->max_send_buffer;
}
#if 0
static size_t get_max_send_queue_soft(struct hub_info* hub)
{
return hub->config->max_send_buffer_soft;
@ -103,11 +102,20 @@ int route_to_user(struct hub_info* hub, struct user* user, struct adc_message* m
free(data);
#endif
int empty = hub_sendq_is_empty(user->net.send_queue);
hub_sendq_add(user->net.send_queue, msg);
/* FIXME: try oportunistic write? */
user_net_io_want_write(user);
if (empty)
{
/* Perform oportunistic write - it might work */
/* FIXME: This is a *BAD* hack! */
net_on_write(user->net.sd, EV_WRITE, user);
}
if (hub_sendq_get_bytes(user->net.send_queue))
{
user_net_io_want_write(user);
}
return 1;
}

View File

@ -19,6 +19,7 @@
#include "uhub.h"
#ifdef DEBUG_SENDQ
static const char* user_log_str(struct user* user)
{
static char buf[128];
@ -32,6 +33,7 @@ static const char* user_log_str(struct user* user)
}
return buf;
}
#endif
struct user* user_create(struct hub_info* hub, int sd)
{
@ -96,7 +98,6 @@ void user_set_state(struct user* user, enum user_state state)
{
if ((user->state == state_cleanup && state != state_disconnected) || (user->state == state_disconnected))
{
puts("PANIC - Ignoring new state");
return;
}