Move bind to Socket

Bind can operate on any IP socket and is not specific to a protocol
pull/2216/head^2
Christopher Haster 2016-03-13 17:57:17 -05:00
parent aea45c88ce
commit 63725d653c
6 changed files with 40 additions and 80 deletions

View File

@ -58,6 +58,27 @@ int Socket::close()
return _iface->socket_close(socket);
}
int Socket::bind(uint16_t port)
{
SocketAddress addr(0, port);
return bind(addr);
}
int Socket::bind(const char *address, uint16_t port)
{
SocketAddress addr(address, port);
return bind(addr);
}
int Socket::bind(const SocketAddress &address)
{
if (!_socket) {
return NSAPI_ERROR_NO_SOCKET;
}
return _iface->socket_bind(_socket, address);
}
void Socket::set_blocking(bool blocking)
{
_blocking = blocking;

View File

@ -33,6 +33,25 @@ public:
*/
virtual int open(NetworkInterface *iface) = 0;
/** Bind a socket to a specific port
* @param port The port to listen for incoming connections on
* @return 0 on success, negative on failure.
*/
int bind(uint16_t port);
/** Bind a socket to a specific port
* @param address The null-terminated address to listen for incoming connections on
* @param port The port to listen for incoming connections on
* @return 0 on success, negative on failure.
*/
int bind(const char *address, uint16_t port);
/** Bind a socket to a specific port
* @param address The SocketAddress to listen for incoming connections on
* @return 0 on success, negative on failure.
*/
int bind(const SocketAddress &address);
/** Set blocking or non-blocking mode of the socket
* @param blocking true for blocking mode, false for non-blocking mode.
*/

View File

@ -31,27 +31,6 @@ int TCPServer::open(NetworkInterface *iface)
return Socket::open(iface, NSAPI_TCP);
}
int TCPServer::bind(uint16_t port)
{
SocketAddress addr(0, port);
return bind(addr);
}
int TCPServer::bind(const char *address, uint16_t port)
{
SocketAddress addr(address, port);
return bind(addr);
}
int TCPServer::bind(const SocketAddress &address)
{
if (!_socket) {
return NSAPI_ERROR_NO_SOCKET;
}
return _iface->socket_bind(_socket, address);
}
int TCPServer::listen(int backlog)
{
if (!_socket) {

View File

@ -36,25 +36,6 @@ public:
*/
virtual int open(NetworkInterface *iface);
/** Bind a TCP Server to a specific port
* @param port The port to listen for incoming connections on
* @return 0 on success, negative on failure.
*/
int bind(uint16_t port);
/** Bind a TCP Server to a local address
* @param address The null-terminated address to listen for incoming connections on
* @param port The port to listen for incoming connections on
* @return 0 on success, negative on failure.
*/
int bind(const char *address, uint16_t port);
/** Bind a TCP Server to a local address
* @param address The SocketAddress to listen for incoming connections on
* @return 0 on success, negative on failure.
*/
int bind(const SocketAddress &address);
/** Start listening for incoming connections
* @param backlog Number of pending connections that can be queued up at any
* one time [Default: 1]

View File

@ -31,27 +31,6 @@ int UDPSocket::open(NetworkInterface *iface)
return Socket::open(iface, NSAPI_UDP);
}
int UDPSocket::bind(uint16_t port)
{
SocketAddress addr(0, port);
return bind(addr);
}
int UDPSocket::bind(const char *address, uint16_t port)
{
SocketAddress addr(address, port);
return bind(addr);
}
int UDPSocket::bind(const SocketAddress &address)
{
if (!_socket) {
return NSAPI_ERROR_NO_SOCKET;
}
return _iface->socket_bind(_socket, address);
}
int UDPSocket::sendto(const char *host, uint16_t port, const void *data, unsigned size)
{
SocketAddress addr(_iface, host, port);

View File

@ -34,25 +34,6 @@ public:
*/
virtual int open(NetworkInterface *iface);
/** Bind a UDP Server Socket to a specific port
* @param port The port to listen for incoming connections on
* @return 0 on success, negative on failure.
*/
int bind(uint16_t port);
/** Bind a UDP Server Socket to a local address
* @param address The null-terminated address to listen for incoming connections on
* @param port The port to listen for incoming connections on
* @return 0 on success, negative on failure.
*/
int bind(const char *address, uint16_t port);
/** Bind a UDP Server Socket to a local address
* @param address The SocketAddress to listen for incoming connections on
* @return 0 on success, negative on failure.
*/
int bind(const SocketAddress &address);
/** Send a packet to a remote endpoint
* @param host The host to connect to. It can either be an IP Address
* or a hostname that will be resolved with DNS