Beispiel #1
0
size_t net_peer_recv(net_peer_t* peer, void* buf, size_t len, int64_t deadline) {
	switch(peer->type) {
		case NET_PROTO_UNIX:
			return unixrecv((unixsock)peer->socket, buf, len, deadline);
		case NET_PROTO_TCP:
			return tcprecv((tcpsock)peer->socket, buf, len, deadline);
		case NET_PROTO_UDP:
			return udprecv((udpsock)peer->socket, 0, buf, len, deadline);
	}

	return 0;
}
Beispiel #2
0
size_t unixrecvuntil(unixsock s, void *buf, size_t len,
      const char *delims, size_t delimcount, int64_t deadline) {
    if(s->type != MILL_UNIXCONN)
        mill_panic("trying to receive from an unconnected socket");
    unsigned char *pos = (unsigned char*)buf;
    size_t i;
    for(i = 0; i != len; ++i, ++pos) {
        size_t res = unixrecv(s, pos, 1, deadline);
        if(res == 1) {
            size_t j;
            for(j = 0; j != delimcount; ++j)
                if(*pos == delims[j])
                    return i + 1;
        }
        if (errno != 0)
            return i + res;
    }
    errno = ENOBUFS;
    return len;
}