static tree234 *sktree;
+static void uxsel_tell(Actual_Socket s);
+
static int cmpfortree(void *av, void *bv)
{
Actual_Socket a = (Actual_Socket) av, b = (Actual_Socket) bv;
return strerror(error);
}
-SockAddr sk_namelookup(char *host, char **canonicalname)
+SockAddr sk_namelookup(const char *host, char **canonicalname)
{
- SockAddr ret = smalloc(sizeof(struct SockAddr_tag));
+ SockAddr ret = snew(struct SockAddr_tag);
unsigned long a;
struct hostent *h = NULL;
char realhost[8192];
}
ret->address = ntohl(a);
realhost[lenof(realhost)-1] = '\0';
- *canonicalname = smalloc(1+strlen(realhost));
+ *canonicalname = snewn(1+strlen(realhost), char);
strcpy(*canonicalname, realhost);
return ret;
}
-SockAddr sk_nonamelookup(char *host)
+SockAddr sk_nonamelookup(const char *host)
{
- SockAddr ret = smalloc(sizeof(struct SockAddr_tag));
+ SockAddr ret = snew(struct SockAddr_tag);
ret->error = NULL;
ret->family = AF_UNSPEC;
strncpy(ret->hostname, host, lenof(ret->hostname));
/*
* Create Socket structure.
*/
- ret = smalloc(sizeof(struct Socket_tag));
+ ret = snew(struct Socket_tag);
ret->fn = &tcp_fn_table;
ret->error = NULL;
ret->plug = plug;
ret->oobinline = 0;
+ uxsel_tell(ret);
add234(sktree, ret);
return (Socket) ret;
/*
* Create Socket structure.
*/
- ret = smalloc(sizeof(struct Socket_tag));
+ ret = snew(struct Socket_tag);
ret->fn = &tcp_fn_table;
ret->error = NULL;
ret->plug = plug;
ret->writable = 1;
}
+ uxsel_tell(ret);
add234(sktree, ret);
return (Socket) ret;
/*
* Create Socket structure.
*/
- ret = smalloc(sizeof(struct Socket_tag));
+ ret = snew(struct Socket_tag);
ret->fn = &tcp_fn_table;
ret->error = NULL;
ret->plug = plug;
return (Socket) ret;
}
+ uxsel_tell(ret);
add234(sktree, ret);
return (Socket) ret;
{
Actual_Socket s = (Actual_Socket) sock;
+ uxsel_del(s->s);
del234(sktree, s);
close(s->s);
sfree(s);
}
}
}
+ uxsel_tell(s);
}
static int sk_tcp_write(Socket sock, const char *buf, int len)
return s->sending_oob;
}
-int select_result(int fd, int event)
+static int net_select_result(int fd, int event)
{
int ret;
int err;
* asynchronous connection is completed.
*/
s->connected = s->writable = 1;
+ uxsel_tell(s);
break;
} else {
int bufsize_before, bufsize_after;
recv(s->s, &c, 1, MSG_PEEK);
}
s->frozen_readable = 0;
+ uxsel_tell(s);
}
-/*
- * For Unix select()-based frontends: enumerate all sockets
- * currently active, and state whether we currently wish to receive
- * select events on them for reading, writing and exceptional
- * status.
- */
-static void set_rwx(Actual_Socket s, int *rwx)
+static void uxsel_tell(Actual_Socket s)
{
- int val = 0;
+ int rwx = 0;
if (!s->connected)
- val |= 2; /* write == connect */
+ rwx |= 2; /* write == connect */
if (s->connected && !s->frozen)
- val |= 1 | 4; /* read, except */
+ rwx |= 1 | 4; /* read, except */
if (bufchain_size(&s->output_data))
- val |= 2; /* write */
+ rwx |= 2; /* write */
if (s->listener)
- val |= 1; /* read == accept */
- *rwx = val;
-}
-
-int first_socket(int *state, int *rwx)
-{
- Actual_Socket s;
- *state = 0;
- s = index234(sktree, (*state)++);
- if (s)
- set_rwx(s, rwx);
- return s ? s->s : -1;
-}
-
-int next_socket(int *state, int *rwx)
-{
- Actual_Socket s = index234(sktree, (*state)++);
- if (s)
- set_rwx(s, rwx);
- return s ? s->s : -1;
+ rwx |= 1; /* read == accept */
+ uxsel_set(s->s, rwx, net_select_result);
}
int net_service_lookup(char *service)