mirror of https://github.com/ARMmbed/mbed-os.git
Move bind to Socket
Bind can operate on any IP socket and is not specific to a protocolpull/2216/head^2
parent
aea45c88ce
commit
63725d653c
21
Socket.cpp
21
Socket.cpp
|
@ -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;
|
||||
|
|
19
Socket.h
19
Socket.h
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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) {
|
||||
|
|
19
TCPServer.h
19
TCPServer.h
|
@ -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]
|
||||
|
|
|
@ -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);
|
||||
|
|
19
UDPSocket.h
19
UDPSocket.h
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue