wip
Fork of Socket by
Diff: UDPSocket.cpp
- Revision:
- 11:3d83c348fb8b
- Parent:
- 10:d24738f4ef99
- Child:
- 16:2d471deff212
--- a/UDPSocket.cpp Tue Jul 31 11:50:55 2012 +0000 +++ b/UDPSocket.cpp Wed Aug 01 13:02:32 2012 +0000 @@ -50,35 +50,30 @@ } // -1 if unsuccessful, else number of bytes written -int UDPSocket::sendTo(UDPPacket& packet) { +int UDPSocket::sendTo(Endpoint &remote, char *packet, int length) { if (_sock_fd < 0) return -1; if (!_blocking) { TimeInterval timeout(_timeout); if (wait_writable(timeout) != 0) - return -1; + return 0; } - return lwip_sendto(_sock_fd, packet._buffer, packet._length, 0, (const struct sockaddr *) &packet._remoteHost, sizeof(packet._remoteHost)); + return lwip_sendto(_sock_fd, packet, length, 0, (const struct sockaddr *) &remote._remoteHost, sizeof(remote._remoteHost)); } // -1 if unsuccessful, else number of bytes received -int UDPSocket::receiveFrom(UDPPacket& packet) { +int UDPSocket::receiveFrom(Endpoint &remote, char *buffer, int length) { if (_sock_fd < 0) return -1; if (!_blocking) { TimeInterval timeout(_timeout); if (wait_readable(timeout) != 0) - return -1; + return 0; } - - packet.reset_address(); - socklen_t remoteHostLen = sizeof(packet._remoteHost); - return lwip_recvfrom(_sock_fd, packet._buffer, packet._length, 0, (struct sockaddr*) &packet._remoteHost, &remoteHostLen); + remote.reset_address(); + socklen_t remoteHostLen = sizeof(remote._remoteHost); + return lwip_recvfrom(_sock_fd, buffer, length, 0, (struct sockaddr*) &remote._remoteHost, &remoteHostLen); } - -UDPSocket::~UDPSocket() { - close(); //Don't want to leak -}