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 protocol
parent
fa45131245
commit
c4506dc1c0
|
@ -58,6 +58,27 @@ int Socket::close()
|
||||||
return _iface->socket_close(socket);
|
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)
|
void Socket::set_blocking(bool blocking)
|
||||||
{
|
{
|
||||||
_blocking = blocking;
|
_blocking = blocking;
|
||||||
|
|
|
@ -33,6 +33,25 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual int open(NetworkInterface *iface) = 0;
|
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
|
/** Set blocking or non-blocking mode of the socket
|
||||||
* @param blocking true for blocking mode, false for non-blocking mode.
|
* @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);
|
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)
|
int TCPServer::listen(int backlog)
|
||||||
{
|
{
|
||||||
if (!_socket) {
|
if (!_socket) {
|
||||||
|
|
|
@ -36,25 +36,6 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual int open(NetworkInterface *iface);
|
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
|
/** Start listening for incoming connections
|
||||||
* @param backlog Number of pending connections that can be queued up at any
|
* @param backlog Number of pending connections that can be queued up at any
|
||||||
* one time [Default: 1]
|
* one time [Default: 1]
|
||||||
|
|
|
@ -31,27 +31,6 @@ int UDPSocket::open(NetworkInterface *iface)
|
||||||
return Socket::open(iface, NSAPI_UDP);
|
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)
|
int UDPSocket::sendto(const char *host, uint16_t port, const void *data, unsigned size)
|
||||||
{
|
{
|
||||||
SocketAddress addr(_iface, host, port);
|
SocketAddress addr(_iface, host, port);
|
||||||
|
|
|
@ -33,25 +33,6 @@ public:
|
||||||
* @param iface Interface to open socket on
|
* @param iface Interface to open socket on
|
||||||
*/
|
*/
|
||||||
virtual int open(NetworkInterface *iface);
|
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
|
/** Send a packet to a remote endpoint
|
||||||
* @param host The host to connect to. It can either be an IP Address
|
* @param host The host to connect to. It can either be an IP Address
|
||||||
|
|
Loading…
Reference in New Issue