diff options
author | Jan Hutter <jhutter@hsr.ch> | 2005-11-09 09:11:06 +0000 |
---|---|---|
committer | Jan Hutter <jhutter@hsr.ch> | 2005-11-09 09:11:06 +0000 |
commit | 79538669625bbae26fcef5d791b2246242c5a407 (patch) | |
tree | a90b417c1c97b4c209a73d09ecb8189770eb20a3 /Source/charon/socket.c | |
parent | c1ca1ee042d15754ebe5abd47d247d382bd4497a (diff) | |
download | strongswan-79538669625bbae26fcef5d791b2246242c5a407.tar.bz2 strongswan-79538669625bbae26fcef5d791b2246242c5a407.tar.xz |
- changed memory allocator functions to own allocator calls
Diffstat (limited to 'Source/charon/socket.c')
-rw-r--r-- | Source/charon/socket.c | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/Source/charon/socket.c b/Source/charon/socket.c index f89822511..782a349b2 100644 --- a/Source/charon/socket.c +++ b/Source/charon/socket.c @@ -1,10 +1,10 @@ /** * @file socket.c - * + * * @brief management of sockets - * + * * receiver reads from here, sender writes to here - * + * */ /* @@ -42,7 +42,7 @@ struct private_socket_s{ * public functions */ socket_t public; - + /** * currently we only have one socket, maybe more in the future ? */ @@ -57,98 +57,98 @@ status_t receiver(private_socket_t *this, packet_t **packet) char buffer[MAX_PACKET]; int oldstate; packet_t *pkt = packet_create(AF_INET); - - + + /* add packet destroy handler for cancellation, enable cancellation */ pthread_cleanup_push((void(*)(void*))pkt->destroy, (void*)pkt); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate); - + /* do the read */ - pkt->data.len = recvfrom(this->socket_fd, buffer, MAX_PACKET, 0, + pkt->data.len = recvfrom(this->socket_fd, buffer, MAX_PACKET, 0, &(pkt->source), &(pkt->sockaddr_len)); - + /* reset cancellation, remove packet destroy handler (without executing) */ pthread_setcancelstate(oldstate, NULL); pthread_cleanup_pop(0); - - - /* TODO: get senders destination address, using + + + /* TODO: get senders destination address, using * IP_PKTINFO and recvmsg */ - + if (pkt->data.len < 0) { pkt->destroy(pkt); /* TODO: log detailed error */ return FAILED; } - + /* fill in packet */ - pkt->data.ptr = alloc_bytes(pkt->data.len, "data in packet_t"); + pkt->data.ptr = allocator_alloc(pkt->data.len, "data in packet_t"); memcpy(pkt->data.ptr, buffer, pkt->data.len); - + /* return packet */ *packet = pkt; - - return SUCCESS; + + return SUCCESS; } - + /** * implementation of socket_t.send */ -status_t sender(private_socket_t *this, packet_t *packet) +status_t sender(private_socket_t *this, packet_t *packet) { ssize_t bytes_sent; - + /* send data */ - bytes_sent = sendto(this->socket_fd, packet->data.ptr, packet->data.len, + bytes_sent = sendto(this->socket_fd, packet->data.ptr, packet->data.len, 0, &(packet->destination), packet->sockaddr_len); - - if (bytes_sent != packet->data.len) + + if (bytes_sent != packet->data.len) { /* TODO: log detailed error */ return FAILED; } return SUCCESS; } - + /** * implementation of socket_t.destroy */ status_t destroy(private_socket_t *this) { close(this->socket_fd); - pfree(this); - + allocator_free(this); + return SUCCESS; } socket_t *socket_create(u_int16_t port) { - private_socket_t *this = alloc_thing(private_socket_t, "private_socket_t"); + private_socket_t *this = allocator_alloc_thing(private_socket_t, "private_socket_t"); struct sockaddr_in addr; - + /* public functions */ this->public.send = (status_t(*)(socket_t*, packet_t*))sender; this->public.receive = (status_t(*)(socket_t*, packet_t**))receiver; this->public.destroy = (status_t(*)(socket_t*))destroy; - + /* create default ipv4 socket */ this->socket_fd = socket(PF_INET, SOCK_DGRAM, 0); if (this->socket_fd < 0) { - pfree(this); + allocator_free(this); /* TODO: log detailed error */ return NULL; - } - + } + /* bind socket to all interfaces */ addr.sin_family = AF_INET; addr.sin_addr.s_addr = INADDR_ANY; addr.sin_port = htons(port); if (bind(this->socket_fd,(struct sockaddr*)&addr, sizeof(addr)) < 0) { - pfree(this); + allocator_free(this); /* TODO: log detailed error */ return NULL; } - + return (socket_t*)this; } |