Branch merge.
This commit is contained in:
commit
c3fed903fd
7 changed files with 57 additions and 16 deletions
7
IDEAS
7
IDEAS
|
@ -1,3 +1,10 @@
|
||||||
|
Important stuff:
|
||||||
|
- our I/O operates on raw fds. we should use fde_t's everywhere so that
|
||||||
|
lookups are less necessary and so that I/O is done using the virtual functors,
|
||||||
|
IOFuncRead and IOFuncWrite.
|
||||||
|
- implement comm_get_io_direction(fde_t *) and use it to determine how to reschedule
|
||||||
|
I/O direction when needed.
|
||||||
|
|
||||||
Some of this may not be possible to do in 2.3...
|
Some of this may not be possible to do in 2.3...
|
||||||
|
|
||||||
- go TS6 only? [partially done; TS6 is always enabled now]
|
- go TS6 only? [partially done; TS6 is always enabled now]
|
||||||
|
|
|
@ -58,6 +58,26 @@ static void comm_connect_dns_callback(void *vptr, struct DNSReply *reply);
|
||||||
static PF comm_connect_tryconnect;
|
static PF comm_connect_tryconnect;
|
||||||
static int comm_max_connections = 0;
|
static int comm_max_connections = 0;
|
||||||
|
|
||||||
|
static int
|
||||||
|
comm_read_raw(fde_t *F, void *buf, size_t count)
|
||||||
|
{
|
||||||
|
s_assert(F != NULL);
|
||||||
|
s_assert(buf != NULL);
|
||||||
|
s_assert(count > 0);
|
||||||
|
|
||||||
|
return read(F->fd, buf, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
comm_write_raw(fde_t *F, const void *buf, size_t count)
|
||||||
|
{
|
||||||
|
s_assert(F != NULL);
|
||||||
|
s_assert(buf != NULL);
|
||||||
|
s_assert(count > 0);
|
||||||
|
|
||||||
|
return write(F->fd, buf, count);
|
||||||
|
}
|
||||||
|
|
||||||
inline fde_t *
|
inline fde_t *
|
||||||
comm_locate_fd(int fd)
|
comm_locate_fd(int fd)
|
||||||
{
|
{
|
||||||
|
@ -85,8 +105,12 @@ comm_add_fd(int fd)
|
||||||
if (F != NULL)
|
if (F != NULL)
|
||||||
return F;
|
return F;
|
||||||
|
|
||||||
F = calloc(sizeof(fde_t), 1);
|
F = MyMalloc(sizeof(fde_t));
|
||||||
F->fd = fd;
|
F->fd = fd;
|
||||||
|
|
||||||
|
F->read_impl = comm_read_raw;
|
||||||
|
F->write_impl = comm_write_raw;
|
||||||
|
|
||||||
list = &fd_table[fd % FD_HASH_SIZE];
|
list = &fd_table[fd % FD_HASH_SIZE];
|
||||||
dlinkAdd(F, &F->node, list);
|
dlinkAdd(F, &F->node, list);
|
||||||
|
|
||||||
|
|
|
@ -32,9 +32,15 @@
|
||||||
#include "ircd_defs.h"
|
#include "ircd_defs.h"
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
|
|
||||||
|
typedef struct _fde fde_t;
|
||||||
|
|
||||||
/* Callback for completed IO events */
|
/* Callback for completed IO events */
|
||||||
typedef void PF(int fd, void *);
|
typedef void PF(int fd, void *);
|
||||||
|
|
||||||
|
/* virtual function types for I/O --nenolod */
|
||||||
|
typedef int IOFuncRead(fde_t *, void *buf, size_t count);
|
||||||
|
typedef int IOFuncWrite(fde_t *, const void *buf, size_t count);
|
||||||
|
|
||||||
/* Callback for completed connections */
|
/* Callback for completed connections */
|
||||||
/* int fd, int status, void * */
|
/* int fd, int status, void * */
|
||||||
typedef void CNCB(int fd, int, void *);
|
typedef void CNCB(int fd, int, void *);
|
||||||
|
@ -76,8 +82,6 @@ typedef enum fdlist_t
|
||||||
}
|
}
|
||||||
fdlist_t;
|
fdlist_t;
|
||||||
|
|
||||||
typedef struct _fde fde_t;
|
|
||||||
|
|
||||||
|
|
||||||
extern int highest_fd;
|
extern int highest_fd;
|
||||||
extern int number_fd;
|
extern int number_fd;
|
||||||
|
@ -96,16 +100,24 @@ struct _fde
|
||||||
fdlist_t list; /* Which list this FD should sit on */
|
fdlist_t list; /* Which list this FD should sit on */
|
||||||
int comm_index; /* where in the poll list we live */
|
int comm_index; /* where in the poll list we live */
|
||||||
char desc[FD_DESC_SZ];
|
char desc[FD_DESC_SZ];
|
||||||
|
|
||||||
PF *read_handler;
|
PF *read_handler;
|
||||||
void *read_data;
|
void *read_data;
|
||||||
|
|
||||||
PF *write_handler;
|
PF *write_handler;
|
||||||
void *write_data;
|
void *write_data;
|
||||||
|
|
||||||
PF *timeout_handler;
|
PF *timeout_handler;
|
||||||
void *timeout_data;
|
void *timeout_data;
|
||||||
time_t timeout;
|
time_t timeout;
|
||||||
|
|
||||||
PF *flush_handler;
|
PF *flush_handler;
|
||||||
void *flush_data;
|
void *flush_data;
|
||||||
time_t flush_timeout;
|
time_t flush_timeout;
|
||||||
|
|
||||||
|
IOFuncRead *read_impl;
|
||||||
|
IOFuncWrite *write_impl;
|
||||||
|
|
||||||
struct DNSQuery *dns_query;
|
struct DNSQuery *dns_query;
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
|
|
|
@ -623,7 +623,7 @@ linebuf_putmsg(buf_head_t * bufhead, const char *format, va_list * va_args,
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int
|
int
|
||||||
linebuf_flush(int fd, buf_head_t * bufhead)
|
linebuf_flush(fde_t *fd, buf_head_t * bufhead)
|
||||||
{
|
{
|
||||||
buf_line_t *bufline;
|
buf_line_t *bufline;
|
||||||
int retval;
|
int retval;
|
||||||
|
@ -652,7 +652,7 @@ linebuf_flush(int fd, buf_head_t * bufhead)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now, try writing data */
|
/* Now, try writing data */
|
||||||
retval = send(fd, bufline->buf + bufhead->writeofs, bufline->len - bufhead->writeofs, 0);
|
retval = fd->write_impl(fd, bufline->buf + bufhead->writeofs, bufline->len - bufhead->writeofs);
|
||||||
|
|
||||||
if(retval <= 0)
|
if(retval <= 0)
|
||||||
return retval;
|
return retval;
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#define __LINEBUF_H__
|
#define __LINEBUF_H__
|
||||||
|
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
|
#include "commio.h"
|
||||||
|
|
||||||
/* How big we want a buffer - 510 data bytes, plus space for a '\0' */
|
/* How big we want a buffer - 510 data bytes, plus space for a '\0' */
|
||||||
#define BUF_DATA_SIZE 511
|
#define BUF_DATA_SIZE 511
|
||||||
|
@ -80,7 +81,7 @@ extern void linebuf_donebuf(buf_head_t *);
|
||||||
extern int linebuf_parse(buf_head_t *, char *, int, int);
|
extern int linebuf_parse(buf_head_t *, char *, int, int);
|
||||||
extern int linebuf_get(buf_head_t *, char *, int, int, int);
|
extern int linebuf_get(buf_head_t *, char *, int, int, int);
|
||||||
extern void linebuf_putmsg(buf_head_t *, const char *, va_list *, const char *, ...);
|
extern void linebuf_putmsg(buf_head_t *, const char *, va_list *, const char *, ...);
|
||||||
extern int linebuf_flush(int, buf_head_t *);
|
extern int linebuf_flush(fde_t *, buf_head_t *);
|
||||||
extern void linebuf_attach(buf_head_t *, buf_head_t *);
|
extern void linebuf_attach(buf_head_t *, buf_head_t *);
|
||||||
extern void count_linebuf_memory(size_t *, size_t *);
|
extern void count_linebuf_memory(size_t *, size_t *);
|
||||||
#endif
|
#endif
|
||||||
|
|
11
src/gnutls.c
11
src/gnutls.c
|
@ -23,15 +23,8 @@
|
||||||
|
|
||||||
#ifdef GNUTLS
|
#ifdef GNUTLS
|
||||||
|
|
||||||
#include <stdio.h>
|
#include "stdinc.h"
|
||||||
#include <stdlib.h>
|
#include "config.h"
|
||||||
#include <errno.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <gnutls/gnutls.h>
|
#include <gnutls/gnutls.h>
|
||||||
#include <gcrypt.h> /* for gcry_control */
|
#include <gcrypt.h> /* for gcry_control */
|
||||||
|
|
||||||
|
|
|
@ -168,6 +168,10 @@ send_queued_write(int fd, void *data)
|
||||||
#ifdef USE_IODEBUG_HOOKS
|
#ifdef USE_IODEBUG_HOOKS
|
||||||
hook_data_int hd;
|
hook_data_int hd;
|
||||||
#endif
|
#endif
|
||||||
|
fde_t *F = comm_locate_fd(to->localClient->fd);
|
||||||
|
if (!F)
|
||||||
|
return;
|
||||||
|
|
||||||
/* cant write anything to a dead socket. */
|
/* cant write anything to a dead socket. */
|
||||||
if(IsIOError(to))
|
if(IsIOError(to))
|
||||||
return;
|
return;
|
||||||
|
@ -182,7 +186,7 @@ send_queued_write(int fd, void *data)
|
||||||
if(linebuf_len(&to->localClient->buf_sendq))
|
if(linebuf_len(&to->localClient->buf_sendq))
|
||||||
{
|
{
|
||||||
while ((retlen =
|
while ((retlen =
|
||||||
linebuf_flush(to->localClient->fd, &to->localClient->buf_sendq)) > 0)
|
linebuf_flush(F, &to->localClient->buf_sendq)) > 0)
|
||||||
{
|
{
|
||||||
/* We have some data written .. update counters */
|
/* We have some data written .. update counters */
|
||||||
#ifdef USE_IODEBUG_HOOKS
|
#ifdef USE_IODEBUG_HOOKS
|
||||||
|
|
Loading…
Reference in a new issue