client: renamed Interface to struct client

Second patch: rename the internal struct name.  We will eventually
export this type as an opaque forward-declared struct later, so we
can pass a struct pointer instead of a file descriptor, which would
save us an expensive linear lookup.
This commit is contained in:
Max Kellermann 2008-08-28 20:02:58 +02:00
parent deb29e0884
commit fe03cb9549

View File

@ -59,7 +59,7 @@ static struct strnode *list_cache;
static struct strnode *list_cache_head; static struct strnode *list_cache_head;
static struct strnode *list_cache_tail; static struct strnode *list_cache_tail;
typedef struct _Interface { struct client {
char buffer[INTERFACE_MAX_BUFFER_LENGTH]; char buffer[INTERFACE_MAX_BUFFER_LENGTH];
size_t bufferLength; size_t bufferLength;
size_t bufferPos; size_t bufferPos;
@ -81,16 +81,16 @@ typedef struct _Interface {
size_t send_buf_used; /* bytes used this instance */ size_t send_buf_used; /* bytes used this instance */
size_t send_buf_size; /* bytes usable this instance */ size_t send_buf_size; /* bytes usable this instance */
size_t send_buf_alloc; /* bytes actually allocated */ size_t send_buf_alloc; /* bytes actually allocated */
} Interface; };
static Interface *interfaces; static struct client *interfaces;
static void flushInterfaceBuffer(Interface * interface); static void flushInterfaceBuffer(struct client *interface);
static void printInterfaceOutBuffer(Interface * interface); static void printInterfaceOutBuffer(struct client *interface);
#ifdef SO_SNDBUF #ifdef SO_SNDBUF
static size_t get_default_snd_buf_size(Interface * interface) static size_t get_default_snd_buf_size(struct client *interface)
{ {
int new_size; int new_size;
socklen_t sockOptLen = sizeof(int); socklen_t sockOptLen = sizeof(int);
@ -106,13 +106,13 @@ static size_t get_default_snd_buf_size(Interface * interface)
return INTERFACE_DEFAULT_OUT_BUFFER_SIZE; return INTERFACE_DEFAULT_OUT_BUFFER_SIZE;
} }
#else /* !SO_SNDBUF */ #else /* !SO_SNDBUF */
static size_t get_default_snd_buf_size(Interface * interface) static size_t get_default_snd_buf_size(struct client *interface)
{ {
return INTERFACE_DEFAULT_OUT_BUFFER_SIZE; return INTERFACE_DEFAULT_OUT_BUFFER_SIZE;
} }
#endif /* !SO_SNDBUF */ #endif /* !SO_SNDBUF */
static void set_send_buf_size(Interface * interface) static void set_send_buf_size(struct client *interface)
{ {
size_t new_size = get_default_snd_buf_size(interface); size_t new_size = get_default_snd_buf_size(interface);
if (interface->send_buf_size != new_size) { if (interface->send_buf_size != new_size) {
@ -127,7 +127,7 @@ static void set_send_buf_size(Interface * interface)
} }
} }
static void openInterface(Interface * interface, int fd) static void openInterface(struct client *interface, int fd)
{ {
assert(interface->fd < 0); assert(interface->fd < 0);
@ -168,7 +168,7 @@ static void free_cmd_list(struct strnode *list)
} }
} }
static void cmd_list_clone(Interface * interface) static void cmd_list_clone(struct client *interface)
{ {
struct strnode *new = dup_strlist(interface->cmd_list); struct strnode *new = dup_strlist(interface->cmd_list);
free_cmd_list(interface->cmd_list); free_cmd_list(interface->cmd_list);
@ -181,7 +181,7 @@ static void cmd_list_clone(Interface * interface)
interface->cmd_list_tail = new; interface->cmd_list_tail = new;
} }
static void new_cmd_list_ptr(Interface * interface, char *s, const int size) static void new_cmd_list_ptr(struct client *interface, char *s, const int size)
{ {
int i; int i;
struct strnode *new; struct strnode *new;
@ -209,7 +209,7 @@ out:
interface->cmd_list = interface->cmd_list_tail = new; interface->cmd_list = interface->cmd_list_tail = new;
} }
static void closeInterface(Interface * interface) static void closeInterface(struct client *interface)
{ {
struct sllnode *buf; struct sllnode *buf;
if (interface->fd < 0) if (interface->fd < 0)
@ -284,7 +284,7 @@ void openAInterface(int fd, const struct sockaddr *addr)
} }
} }
static int processLineOfInput(Interface * interface) static int processLineOfInput(struct client *interface)
{ {
int ret = 1; int ret = 1;
char *line = interface->buffer + interface->bufferPos; char *line = interface->buffer + interface->bufferPos;
@ -355,7 +355,7 @@ static int processLineOfInput(Interface * interface)
return ret; return ret;
} }
static int processBytesRead(Interface * interface, int bytesRead) static int processBytesRead(struct client *interface, int bytesRead)
{ {
int ret = 0; int ret = 0;
char *buf_tail = &(interface->buffer[interface->bufferLength - 1]); char *buf_tail = &(interface->buffer[interface->bufferLength - 1]);
@ -403,7 +403,7 @@ static int processBytesRead(Interface * interface, int bytesRead)
return ret; return ret;
} }
static int interfaceReadInput(Interface * interface) static int interfaceReadInput(struct client *interface)
{ {
int bytesRead; int bytesRead;
@ -586,7 +586,7 @@ void initInterfaces(void)
interface_max_output_buffer_size = tmp * 1024; interface_max_output_buffer_size = tmp * 1024;
} }
interfaces = xmalloc(sizeof(Interface) * interface_max_connections); interfaces = xmalloc(sizeof(interfaces[0]) * interface_max_connections);
list_cache = xcalloc(interface_list_cache_size, sizeof(struct strnode)); list_cache = xcalloc(interface_list_cache_size, sizeof(struct strnode));
list_cache_head = &(list_cache[0]); list_cache_head = &(list_cache[0]);
@ -641,7 +641,7 @@ void closeOldInterfaces(void)
} }
} }
static void flushInterfaceBuffer(Interface * interface) static void flushInterfaceBuffer(struct client *interface)
{ {
struct sllnode *buf; struct sllnode *buf;
ssize_t ret = 0; ssize_t ret = 0;
@ -693,7 +693,7 @@ int interfacePrintWithFD(int fd, const char *buffer, size_t buflen)
{ {
static unsigned int i; static unsigned int i;
size_t copylen; size_t copylen;
Interface *interface; struct client *interface;
assert(fd >= 0); assert(fd >= 0);
@ -732,7 +732,7 @@ int interfacePrintWithFD(int fd, const char *buffer, size_t buflen)
return 0; return 0;
} }
static void printInterfaceOutBuffer(Interface * interface) static void printInterfaceOutBuffer(struct client *interface)
{ {
ssize_t ret; ssize_t ret;
struct sllnode *buf; struct sllnode *buf;