mirror of https://github.com/ARMmbed/mbed-os.git
Added better support for SocketAddress/string addresses/ports
parent
e47bb97eff
commit
1aa0b6ce2a
|
|
@ -223,20 +223,20 @@ int LWIPInterface::socket_get_option(void *handle, int optname, void *optval, un
|
||||||
return NSAPI_ERROR_UNSUPPORTED;
|
return NSAPI_ERROR_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LWIPInterface::socket_bind(void *handle, int port)
|
int LWIPInterface::socket_bind(void *handle, const SocketAddress &address)
|
||||||
{
|
{
|
||||||
struct lwip_socket *s = (struct lwip_socket *)handle;
|
struct lwip_socket *s = (struct lwip_socket *)handle;
|
||||||
ip_addr_t ip_addr = ip_addr_any;
|
ip_addr_t ip_addr = ip_addr_any; // TODO use address
|
||||||
|
|
||||||
switch (s->proto) {
|
switch (s->proto) {
|
||||||
case NSAPI_UDP:
|
case NSAPI_UDP:
|
||||||
if (udp_bind(s->udp, &ip_addr, port)) {
|
if (udp_bind(s->udp, &ip_addr, address.get_port())) {
|
||||||
return NSAPI_ERROR_DEVICE_ERROR;
|
return NSAPI_ERROR_DEVICE_ERROR;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case NSAPI_TCP:
|
case NSAPI_TCP:
|
||||||
if (tcp_bind(s->tcp, &ip_addr, port)) {
|
if (tcp_bind(s->tcp, &ip_addr, address.get_port())) {
|
||||||
return NSAPI_ERROR_DEVICE_ERROR;
|
return NSAPI_ERROR_DEVICE_ERROR;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -83,11 +83,11 @@ protected:
|
||||||
virtual int socket_get_option(void *handle, int optname, void *optval, unsigned int *optlen);
|
virtual int socket_get_option(void *handle, int optname, void *optval, unsigned int *optlen);
|
||||||
|
|
||||||
/** Bind a server socket to a specific port
|
/** Bind a server socket to a specific port
|
||||||
\param handle Socket handle
|
* @param handle Socket handle
|
||||||
\param port The port to listen for incoming connections on
|
* @param address Local address to listen for incoming connections on
|
||||||
\return 0 on success, negative on failure.
|
* @return 0 on success, negative on failure.
|
||||||
*/
|
*/
|
||||||
virtual int socket_bind(void *handle, int port);
|
virtual int socket_bind(void *handle, const SocketAddress &address);
|
||||||
|
|
||||||
/** Start listening for incoming connections
|
/** Start listening for incoming connections
|
||||||
\param handle Socket handle
|
\param handle Socket handle
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue