mirror of https://github.com/ARMmbed/mbed-os.git
Renamed NetworkInterface create/destroy methods to match Socket methods
- socket_create -> socket_open - socket_destroy -> socket_closepull/2216/head^2
parent
dfc1ca4cef
commit
1b368cf525
|
@ -89,16 +89,20 @@ protected:
|
|||
friend class TCPSocket;
|
||||
friend class TCPServer;
|
||||
|
||||
/** Create a socket
|
||||
* @param proto The type of socket to open, TCP or UDP
|
||||
* @return The alocated socket or null on failure
|
||||
/** Open a socket
|
||||
* @param handle Handle in which to store new socket
|
||||
* @param proto Type of socket to open, NSAPI_TCP or NSAPI_UDP
|
||||
* @return 0 on success, negative on failure
|
||||
*/
|
||||
virtual void *socket_create(nsapi_protocol_t proto) = 0;
|
||||
virtual int socket_open(void **handle, nsapi_protocol_t proto) = 0;
|
||||
|
||||
/** Destroy a socket
|
||||
* @param socket Previously allocated socket
|
||||
/** Close the socket
|
||||
* @param handle Socket handle
|
||||
* @return 0 on success, negative on failure
|
||||
* @note On failure, any memory associated with the socket must still
|
||||
* be cleaned up
|
||||
*/
|
||||
virtual void socket_destroy(void *handle) = 0;
|
||||
virtual int socket_close(void *handle) = 0;
|
||||
|
||||
/** Set socket options
|
||||
* @param handle Socket handle
|
||||
|
@ -147,13 +151,13 @@ protected:
|
|||
virtual bool socket_is_connected(void *handle) = 0;
|
||||
|
||||
/** Accept a new connection.
|
||||
* @param handle Socket handle
|
||||
* @param socket A TCPSocket instance that will handle the incoming connection.
|
||||
* @return 0 on success, negative on failure.
|
||||
* @param handle Handle in which to store new socket
|
||||
* @param server Socket handle to server to accept from
|
||||
* @return 0 on success, negative on failure
|
||||
* @note This call is not-blocking, if this call would block, must
|
||||
* immediately return NSAPI_ERROR_WOULD_WAIT
|
||||
*/
|
||||
virtual int socket_accept(void *handle, void **connection) = 0;
|
||||
virtual int socket_accept(void **handle, void *server) = 0;
|
||||
|
||||
/** Send data to the remote host
|
||||
* @param handle Socket handle
|
||||
|
@ -199,11 +203,6 @@ protected:
|
|||
*/
|
||||
virtual int socket_recvfrom(void *handle, SocketAddress *address, void *buffer, unsigned size) = 0;
|
||||
|
||||
/** Close the socket
|
||||
* @param handle Socket handle
|
||||
*/
|
||||
virtual int socket_close(void *handle) = 0;
|
||||
|
||||
/** Register a callback on state change of the socket
|
||||
* @param handle Socket handle
|
||||
* @param callback Function to call on state change
|
||||
|
|
22
Socket.cpp
22
Socket.cpp
|
@ -34,8 +34,17 @@ Socket::~Socket()
|
|||
int Socket::open(NetworkInterface *iface, nsapi_protocol_t proto)
|
||||
{
|
||||
_iface = iface;
|
||||
_socket = _iface->socket_create(proto);
|
||||
|
||||
void *socket;
|
||||
int err = _iface->socket_open(&socket, proto);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
_socket = socket;
|
||||
_iface->socket_attach(_socket, &Socket::thunk, this);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Socket::close()
|
||||
|
@ -44,14 +53,9 @@ int Socket::close()
|
|||
return 0;
|
||||
}
|
||||
|
||||
int err = _iface->socket_close(_socket);
|
||||
if (!err) {
|
||||
void *socket = _socket;
|
||||
_socket = 0;
|
||||
_iface->socket_destroy(socket);
|
||||
}
|
||||
|
||||
return err;
|
||||
void *socket = _socket;
|
||||
_socket = 0;
|
||||
return _iface->socket_close(socket);
|
||||
}
|
||||
|
||||
void Socket::set_blocking(bool blocking)
|
||||
|
|
|
@ -64,9 +64,8 @@ int TCPServer::accept(TCPSocket *connection)
|
|||
}
|
||||
|
||||
void *socket;
|
||||
int err = _iface->socket_accept(_socket, &socket);
|
||||
|
||||
if (err > 0) {
|
||||
int err = _iface->socket_accept(&socket, _socket);
|
||||
if (!err) {
|
||||
connection->_socket = socket;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue