mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
Extend net_sendbuffer by adding a LINEBUF_REC member and a net_sendbuffer_receive_line
function to read linewise from the associated io channel. Rewrite irc/dcc/proxy read logic on top of it. git-svn-id: file:///var/www/svn.irssi.org/SVN/irssi/trunk@4841 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
9f99376a8a
commit
f053542dcf
@ -22,6 +22,7 @@
|
||||
|
||||
#include "network.h"
|
||||
#include "net-sendbuffer.h"
|
||||
#include "line-split.h"
|
||||
|
||||
static GSList *buffers;
|
||||
|
||||
@ -50,6 +51,7 @@ void net_sendbuffer_destroy(NET_SENDBUF_REC *rec, int close)
|
||||
|
||||
if (rec->send_tag != -1) g_source_remove(rec->send_tag);
|
||||
if (close) net_disconnect(rec->handle);
|
||||
if (rec->readbuffer != NULL) line_split_free(rec->readbuffer);
|
||||
g_free_not_null(rec->buffer);
|
||||
g_free(rec);
|
||||
}
|
||||
@ -142,6 +144,17 @@ int net_sendbuffer_send(NET_SENDBUF_REC *rec, const void *data, int size)
|
||||
return buffer_add(rec, data, size) ? 0 : -1;
|
||||
}
|
||||
|
||||
int net_sendbuffer_receive_line(NET_SENDBUF_REC *rec, char **str, int read_socket)
|
||||
{
|
||||
char tmpbuf[512];
|
||||
int recvlen = 0;
|
||||
|
||||
if (read_socket)
|
||||
recvlen = net_receive(rec->handle, tmpbuf, sizeof(tmpbuf));
|
||||
|
||||
return line_split(tmpbuf, recvlen, str, &rec->readbuffer);
|
||||
}
|
||||
|
||||
/* Flush the buffer, blocks until finished. */
|
||||
void net_sendbuffer_flush(NET_SENDBUF_REC *rec)
|
||||
{
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
struct _NET_SENDBUF_REC {
|
||||
GIOChannel *handle;
|
||||
LINEBUF_REC *readbuffer; /* receive buffer */
|
||||
|
||||
int send_tag;
|
||||
int bufsize;
|
||||
@ -26,6 +27,8 @@ void net_sendbuffer_destroy(NET_SENDBUF_REC *rec, int close);
|
||||
occured. */
|
||||
int net_sendbuffer_send(NET_SENDBUF_REC *rec, const void *data, int size);
|
||||
|
||||
int net_sendbuffer_receive_line(NET_SENDBUF_REC *rec, char **str, int read_socket);
|
||||
|
||||
/* Flush the buffer, blocks until finished. */
|
||||
void net_sendbuffer_flush(NET_SENDBUF_REC *rec);
|
||||
|
||||
|
@ -27,7 +27,6 @@ int connect_tag;
|
||||
int connect_pid;
|
||||
|
||||
RAWLOG_REC *rawlog;
|
||||
LINEBUF_REC *buffer; /* receive buffer */
|
||||
GHashTable *module_data;
|
||||
|
||||
char *version; /* server version */
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include "module.h"
|
||||
#include "signals.h"
|
||||
#include "commands.h"
|
||||
#include "line-split.h"
|
||||
#include "net-disconnect.h"
|
||||
#include "net-nonblock.h"
|
||||
#include "net-sendbuffer.h"
|
||||
@ -536,7 +535,6 @@ int server_unref(SERVER_REC *server)
|
||||
MODULE_DATA_DEINIT(server);
|
||||
server_connect_unref(server->connrec);
|
||||
if (server->rawlog != NULL) rawlog_destroy(server->rawlog);
|
||||
if (server->buffer != NULL) line_split_free(server->buffer);
|
||||
g_free(server->version);
|
||||
g_free(server->away_reason);
|
||||
g_free(server->nick);
|
||||
|
@ -334,7 +334,7 @@ static void sig_server_quit(IRC_SERVER_REC *server, const char *msg)
|
||||
char *str;
|
||||
|
||||
if (!IS_IRC_SERVER(server) || server->handle == NULL ||
|
||||
server->buffer == NULL)
|
||||
server->handle->readbuffer == NULL)
|
||||
return;
|
||||
|
||||
str = g_strdup_printf("QUIT :%s", msg);
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include "modules.h"
|
||||
#include "network.h"
|
||||
#include "net-sendbuffer.h"
|
||||
#include "line-split.h"
|
||||
#include "rawlog.h"
|
||||
#include "misc.h"
|
||||
|
||||
@ -326,28 +325,6 @@ static void irc_server_event(IRC_SERVER_REC *server, const char *line,
|
||||
g_free(recoded_nick);
|
||||
}
|
||||
|
||||
/* Read line from server */
|
||||
static int irc_receive_line(SERVER_REC *server, char **str, int read_socket)
|
||||
{
|
||||
char tmpbuf[512];
|
||||
int recvlen, ret;
|
||||
|
||||
g_return_val_if_fail(server != NULL, -1);
|
||||
g_return_val_if_fail(str != NULL, -1);
|
||||
|
||||
recvlen = !read_socket ? 0 :
|
||||
net_receive(net_sendbuffer_handle(server->handle),
|
||||
tmpbuf, sizeof(tmpbuf));
|
||||
|
||||
ret = line_split(tmpbuf, recvlen, str, &server->buffer);
|
||||
if (ret == -1) {
|
||||
/* connection lost */
|
||||
server->connection_lost = TRUE;
|
||||
server_disconnect(server);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static char *irc_parse_prefix(char *line, char **nick, char **address)
|
||||
{
|
||||
char *p;
|
||||
@ -403,6 +380,7 @@ static void irc_parse_incoming(SERVER_REC *server)
|
||||
{
|
||||
char *str;
|
||||
int count;
|
||||
int ret;
|
||||
|
||||
g_return_if_fail(server != NULL);
|
||||
|
||||
@ -412,7 +390,7 @@ static void irc_parse_incoming(SERVER_REC *server)
|
||||
count = 0;
|
||||
server_ref(server);
|
||||
while (!server->disconnected &&
|
||||
irc_receive_line(server, &str, count < MAX_SOCKET_READS) > 0) {
|
||||
(ret = net_sendbuffer_receive_line(server->handle, &str, count < MAX_SOCKET_READS)) > 0) {
|
||||
rawlog_input(server->rawlog, str);
|
||||
signal_emit_id(signal_server_incoming, 2, server, str);
|
||||
|
||||
@ -421,6 +399,11 @@ static void irc_parse_incoming(SERVER_REC *server)
|
||||
|
||||
count++;
|
||||
}
|
||||
if (ret == -1) {
|
||||
/* connection lost */
|
||||
server->connection_lost = TRUE;
|
||||
server_disconnect(server);
|
||||
}
|
||||
server_unref(server);
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,6 @@
|
||||
#include "recode.h"
|
||||
#include "network.h"
|
||||
#include "net-sendbuffer.h"
|
||||
#include "line-split.h"
|
||||
#include "misc.h"
|
||||
#include "settings.h"
|
||||
|
||||
@ -91,7 +90,6 @@ static void sig_dcc_destroyed(CHAT_DCC_REC *dcc)
|
||||
dcc_remove_chat_refs(dcc);
|
||||
|
||||
if (dcc->sendbuf != NULL) net_sendbuffer_destroy(dcc->sendbuf, FALSE);
|
||||
line_split_free(dcc->readbuf);
|
||||
g_free(dcc->id);
|
||||
}
|
||||
|
||||
@ -297,15 +295,14 @@ static void cmd_ctcp(const char *data, IRC_SERVER_REC *server)
|
||||
/* input function: DCC CHAT received some data.. */
|
||||
void dcc_chat_input(CHAT_DCC_REC *dcc)
|
||||
{
|
||||
char tmpbuf[512], *str;
|
||||
int recvlen, ret;
|
||||
char *str;
|
||||
int ret;
|
||||
|
||||
g_return_if_fail(IS_DCC_CHAT(dcc));
|
||||
|
||||
do {
|
||||
recvlen = net_receive(dcc->handle, tmpbuf, sizeof(tmpbuf));
|
||||
ret = net_sendbuffer_receive_line(dcc->sendbuf, &str, 1);
|
||||
|
||||
ret = line_split(tmpbuf, recvlen, &str, &dcc->readbuf);
|
||||
if (ret == -1) {
|
||||
/* connection lost */
|
||||
dcc->connection_lost = TRUE;
|
||||
|
@ -13,7 +13,6 @@ struct CHAT_DCC_REC {
|
||||
#include "dcc-rec.h"
|
||||
|
||||
char *id; /* unique identifier - usually same as nick. */
|
||||
LINEBUF_REC *readbuf;
|
||||
NET_SENDBUF_REC *sendbuf;
|
||||
|
||||
unsigned int mirc_ctcp:1; /* Send CTCPs without the CTCP_MESSAGE prefix */
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include "commands.h"
|
||||
#include "network.h"
|
||||
#include "net-sendbuffer.h"
|
||||
#include "line-split.h"
|
||||
#include "misc.h"
|
||||
|
||||
#include "irc-servers.h"
|
||||
@ -47,7 +46,6 @@ static void sig_dcc_destroyed(SERVER_DCC_REC *dcc)
|
||||
|
||||
if (dcc->sendbuf != NULL)
|
||||
net_sendbuffer_destroy(dcc->sendbuf, FALSE);
|
||||
line_split_free(dcc->readbuf);
|
||||
}
|
||||
|
||||
/* Start listening for incoming connections */
|
||||
@ -65,15 +63,14 @@ static GIOChannel *dcc_listen_port(GIOChannel *iface, IPADDR *ip, int port)
|
||||
/* input function: DCC SERVER received some data.. */
|
||||
static void dcc_server_input(SERVER_DCC_REC *dcc)
|
||||
{
|
||||
char tmpbuf[512], *str;
|
||||
int recvlen, ret;
|
||||
char *str;
|
||||
int ret;
|
||||
|
||||
g_return_if_fail(IS_DCC_SERVER(dcc));
|
||||
|
||||
do {
|
||||
recvlen = net_receive(dcc->handle, tmpbuf, sizeof(tmpbuf));
|
||||
ret = net_sendbuffer_receive_line(dcc->sendbuf, &str, 1);
|
||||
|
||||
ret = line_split(tmpbuf, recvlen, &str, &dcc->readbuf);
|
||||
if (ret == -1) {
|
||||
/* connection lost */
|
||||
dcc_close(DCC(dcc));
|
||||
|
@ -11,7 +11,6 @@
|
||||
|
||||
struct SERVER_DCC_REC {
|
||||
#include "dcc-rec.h"
|
||||
LINEBUF_REC *readbuf;
|
||||
NET_SENDBUF_REC *sendbuf;
|
||||
|
||||
unsigned int accept_send:1; /* Accept SEND connections */
|
||||
|
@ -50,7 +50,6 @@ static void remove_client(CLIENT_REC *rec)
|
||||
g_free(rec->proxy_address);
|
||||
net_sendbuffer_destroy(rec->handle, TRUE);
|
||||
g_source_remove(rec->recv_tag);
|
||||
line_split_free(rec->buffer);
|
||||
g_free_not_null(rec->nick);
|
||||
g_free_not_null(rec->host);
|
||||
g_free(rec);
|
||||
@ -296,14 +295,13 @@ static void handle_client_cmd(CLIENT_REC *client, char *cmd, char *args,
|
||||
|
||||
static void sig_listen_client(CLIENT_REC *client)
|
||||
{
|
||||
char tmpbuf[1024], *str, *cmd, *args;
|
||||
int ret, recvlen;
|
||||
char *str, *cmd, *args;
|
||||
int ret;
|
||||
|
||||
g_return_if_fail(client != NULL);
|
||||
|
||||
while (g_slist_find(proxy_clients, client) != NULL) {
|
||||
recvlen = net_receive(client->handle->handle, tmpbuf, sizeof(tmpbuf));
|
||||
ret = line_split(tmpbuf, recvlen, &str, &client->buffer);
|
||||
ret = net_sendbuffer_receive_line(client->handle, &str, 1);
|
||||
if (ret == -1) {
|
||||
/* connection lost */
|
||||
remove_client(client);
|
||||
|
@ -3,7 +3,6 @@
|
||||
#define MODULE_NAME "proxy"
|
||||
|
||||
#include "network.h"
|
||||
#include "line-split.h"
|
||||
#include "irc.h"
|
||||
#include "irc-servers.h"
|
||||
|
||||
@ -18,8 +17,6 @@ typedef struct {
|
||||
} LISTEN_REC;
|
||||
|
||||
typedef struct {
|
||||
LINEBUF_REC *buffer;
|
||||
|
||||
char *nick, *host;
|
||||
NET_SENDBUF_REC *handle;
|
||||
int recv_tag;
|
||||
|
Loading…
Reference in New Issue
Block a user