Added better support for SocketAddress/string addresses/ports

pull/2231/head
Christopher Haster 2016-03-13 17:25:05 -05:00
parent e47bb97eff
commit 1aa0b6ce2a
2 changed files with 9 additions and 9 deletions

View File

@ -223,20 +223,20 @@ int LWIPInterface::socket_get_option(void *handle, int optname, void *optval, un
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;
ip_addr_t ip_addr = ip_addr_any;
ip_addr_t ip_addr = ip_addr_any; // TODO use address
switch (s->proto) {
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 0;
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 0;

View File

@ -83,11 +83,11 @@ protected:
virtual int socket_get_option(void *handle, int optname, void *optval, unsigned int *optlen);
/** Bind a server socket to a specific port
\param handle Socket handle
\param port The port to listen for incoming connections on
\return 0 on success, negative on failure.
*/
virtual int socket_bind(void *handle, int port);
* @param handle Socket handle
* @param address Local address to listen for incoming connections on
* @return 0 on success, negative on failure.
*/
virtual int socket_bind(void *handle, const SocketAddress &address);
/** Start listening for incoming connections
\param handle Socket handle