mirror of
https://github.com/irssi/irssi.git
synced 2025-02-02 15:08:01 -05:00
Merge pull request #1017 from horgh/horgh/error-check
Remove unused functions
This commit is contained in:
commit
1247b37ff7
src
@ -25,16 +25,6 @@
|
||||
#include "pidwait.h"
|
||||
#include "net-nonblock.h"
|
||||
|
||||
typedef struct {
|
||||
NET_CALLBACK func;
|
||||
void *data;
|
||||
|
||||
GIOChannel *pipes[2];
|
||||
int port;
|
||||
IPADDR *my_ip;
|
||||
int tag;
|
||||
} SIMPLE_THREAD_REC;
|
||||
|
||||
/* nonblocking gethostbyname(), ip (IPADDR) + error (int, 0 = not error) is
|
||||
written to pipe when found PID of the resolver child is returned */
|
||||
int net_gethostbyname_nonblock(const char *addr, GIOChannel *pipe,
|
||||
@ -63,7 +53,7 @@ int net_gethostbyname_nonblock(const char *addr, GIOChannel *pipe,
|
||||
/* child */
|
||||
srand(time(NULL));
|
||||
|
||||
memset(&rec, 0, sizeof(rec));
|
||||
memset(&rec, 0, sizeof(rec));
|
||||
rec.error = net_gethostbyname(addr, &rec.ip4, &rec.ip6);
|
||||
if (rec.error == 0) {
|
||||
errorstr = NULL;
|
||||
@ -79,7 +69,7 @@ int net_gethostbyname_nonblock(const char *addr, GIOChannel *pipe,
|
||||
rec.errlen = errorstr == NULL ? 0 : strlen(errorstr)+1;
|
||||
}
|
||||
|
||||
g_io_channel_write_block(pipe, &rec, sizeof(rec));
|
||||
g_io_channel_write_block(pipe, &rec, sizeof(rec));
|
||||
if (rec.errlen != 0)
|
||||
g_io_channel_write_block(pipe, (void *) errorstr, rec.errlen);
|
||||
else {
|
||||
@ -129,7 +119,7 @@ int net_gethostbyname_return(GIOChannel *pipe, RESOLVED_IP_REC *rec)
|
||||
/* read error string, if we can't read everything for some
|
||||
reason, just ignore it. */
|
||||
rec->errorstr = g_malloc0(rec->errlen+1);
|
||||
g_io_channel_read_block(pipe, rec->errorstr, rec->errlen);
|
||||
g_io_channel_read_block(pipe, rec->errorstr, rec->errlen);
|
||||
} else {
|
||||
if (rec->host4) {
|
||||
g_io_channel_read_block(pipe, &len, sizeof(int));
|
||||
@ -146,13 +136,6 @@ int net_gethostbyname_return(GIOChannel *pipe, RESOLVED_IP_REC *rec)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Get host name, call func when finished */
|
||||
int net_gethostbyaddr_nonblock(IPADDR *ip, NET_HOST_CALLBACK func, void *data)
|
||||
{
|
||||
/* FIXME: not implemented */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Kill the resolver child */
|
||||
void net_disconnect_nonblock(int pid)
|
||||
{
|
||||
@ -160,89 +143,3 @@ void net_disconnect_nonblock(int pid)
|
||||
|
||||
kill(pid, SIGKILL);
|
||||
}
|
||||
|
||||
static void simple_init(SIMPLE_THREAD_REC *rec, GIOChannel *handle)
|
||||
{
|
||||
g_return_if_fail(rec != NULL);
|
||||
|
||||
g_source_remove(rec->tag);
|
||||
|
||||
if (net_geterror(handle) != 0) {
|
||||
/* failed */
|
||||
g_io_channel_shutdown(handle, TRUE, NULL);
|
||||
g_io_channel_unref(handle);
|
||||
handle = NULL;
|
||||
}
|
||||
|
||||
rec->func(handle, rec->data);
|
||||
g_free(rec);
|
||||
}
|
||||
|
||||
static void simple_readpipe(SIMPLE_THREAD_REC *rec, GIOChannel *pipe)
|
||||
{
|
||||
RESOLVED_IP_REC iprec;
|
||||
GIOChannel *handle;
|
||||
IPADDR *ip;
|
||||
|
||||
g_return_if_fail(rec != NULL);
|
||||
|
||||
g_source_remove(rec->tag);
|
||||
|
||||
net_gethostbyname_return(pipe, &iprec);
|
||||
g_free_not_null(iprec.errorstr);
|
||||
|
||||
g_io_channel_shutdown(rec->pipes[0], TRUE, NULL);
|
||||
g_io_channel_unref(rec->pipes[0]);
|
||||
g_io_channel_shutdown(rec->pipes[1], TRUE, NULL);
|
||||
g_io_channel_unref(rec->pipes[1]);
|
||||
|
||||
ip = iprec.ip4.family != 0 ? &iprec.ip4 : &iprec.ip6;
|
||||
handle = iprec.error == -1 ? NULL :
|
||||
net_connect_ip(ip, rec->port, rec->my_ip);
|
||||
|
||||
g_free_not_null(rec->my_ip);
|
||||
|
||||
if (handle == NULL) {
|
||||
/* failed */
|
||||
rec->func(NULL, rec->data);
|
||||
g_free(rec);
|
||||
return;
|
||||
}
|
||||
|
||||
rec->tag = g_input_add(handle, G_INPUT_READ | G_INPUT_WRITE,
|
||||
(GInputFunction) simple_init, rec);
|
||||
}
|
||||
|
||||
/* Connect to server, call func when finished */
|
||||
int net_connect_nonblock(const char *server, int port, const IPADDR *my_ip,
|
||||
NET_CALLBACK func, void *data)
|
||||
{
|
||||
SIMPLE_THREAD_REC *rec;
|
||||
int fd[2];
|
||||
|
||||
g_return_val_if_fail(server != NULL, FALSE);
|
||||
g_return_val_if_fail(func != NULL, FALSE);
|
||||
|
||||
if (pipe(fd) != 0) {
|
||||
g_warning("net_connect_nonblock(): pipe() failed.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
rec = g_new0(SIMPLE_THREAD_REC, 1);
|
||||
rec->port = port;
|
||||
if (my_ip != NULL) {
|
||||
rec->my_ip = g_malloc(sizeof(IPADDR));
|
||||
memcpy(rec->my_ip, my_ip, sizeof(IPADDR));
|
||||
}
|
||||
rec->func = func;
|
||||
rec->data = data;
|
||||
rec->pipes[0] = g_io_channel_new(fd[0]);
|
||||
rec->pipes[1] = g_io_channel_new(fd[1]);
|
||||
|
||||
/* start nonblocking host name lookup */
|
||||
net_gethostbyname_nonblock(server, rec->pipes[1], 0);
|
||||
rec->tag = g_input_add(rec->pipes[0], G_INPUT_READ,
|
||||
(GInputFunction) simple_readpipe, rec);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -12,29 +12,12 @@ typedef struct {
|
||||
char *host4, *host6; /* dito */
|
||||
} RESOLVED_IP_REC;
|
||||
|
||||
typedef struct {
|
||||
int namelen;
|
||||
char *name;
|
||||
|
||||
int error;
|
||||
int errlen;
|
||||
char *errorstr;
|
||||
} RESOLVED_NAME_REC;
|
||||
|
||||
typedef void (*NET_CALLBACK) (GIOChannel *, void *);
|
||||
typedef void (*NET_HOST_CALLBACK) (RESOLVED_NAME_REC *, void *);
|
||||
|
||||
/* nonblocking gethostbyname(), PID of the resolver child is returned. */
|
||||
int net_gethostbyname_nonblock(const char *addr, GIOChannel *pipe,
|
||||
int reverse_lookup);
|
||||
/* Get host's name, call func when finished */
|
||||
int net_gethostbyaddr_nonblock(IPADDR *ip, NET_HOST_CALLBACK func, void *data);
|
||||
/* get the resolved IP address. returns -1 if some error occurred with read() */
|
||||
int net_gethostbyname_return(GIOChannel *pipe, RESOLVED_IP_REC *rec);
|
||||
|
||||
/* Connect to server, call func when finished */
|
||||
int net_connect_nonblock(const char *server, int port, const IPADDR *my_ip,
|
||||
NET_CALLBACK func, void *data);
|
||||
/* Kill the resolver child */
|
||||
void net_disconnect_nonblock(int pid);
|
||||
|
||||
|
@ -21,7 +21,7 @@ unsigned int no_reconnect:1; /* Don't reconnect to server */
|
||||
NET_SENDBUF_REC *handle;
|
||||
int readtag; /* input tag */
|
||||
|
||||
/* for net_connect_nonblock() */
|
||||
/* for net_gethostbyname_return() */
|
||||
GIOChannel *connect_pipe[2];
|
||||
int connect_tag;
|
||||
int connect_pid;
|
||||
|
@ -361,7 +361,7 @@ static void dcc_chat_listen(CHAT_DCC_REC *dcc)
|
||||
signal_emit("dcc connected", 1, dcc);
|
||||
}
|
||||
|
||||
/* callback: DCC CHAT - net_connect_nonblock() finished */
|
||||
/* callback: DCC CHAT - connect finished */
|
||||
static void sig_chat_connected(CHAT_DCC_REC *dcc)
|
||||
{
|
||||
g_return_if_fail(IS_DCC_CHAT(dcc));
|
||||
|
Loading…
x
Reference in New Issue
Block a user