Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: Socket.cpp
- Revision:
- 18:0a988e4abb72
- Parent:
- 17:b1d417383c0d
- Child:
- 19:cad29ce6a01c
--- a/Socket.cpp Tue Apr 19 18:20:38 2016 -0500
+++ b/Socket.cpp Tue Apr 19 18:22:15 2016 -0500
@@ -16,12 +16,12 @@
#include "Socket.h"
-Socket::Socket(NetworkInterface *iface, nsapi_protocol_t proto)
- : _iface(iface)
+Socket::Socket()
+ : _iface(0)
+ , _socket(0)
, _blocking(true)
, _timeout(0)
{
- _socket = _iface->socket_create(proto);
}
Socket::~Socket()
@@ -31,6 +31,28 @@
}
}
+int Socket::open(NetworkInterface *iface, nsapi_protocol_t proto)
+{
+ _iface = iface;
+ _socket = _iface->socket_create(proto);
+}
+
+int Socket::close(bool shutdown)
+{
+ if (!_socket) {
+ return 0;
+ }
+
+ int err = _iface->socket_close(_socket, shutdown);
+ if (!err) {
+ void *socket = _socket;
+ _socket = 0;
+ _iface->socket_destroy(socket);
+ }
+
+ return err;
+}
+
void Socket::set_blocking(bool blocking)
{
_blocking = blocking;
@@ -59,22 +81,6 @@
return _iface->socket_get_option(_socket, optname, optval, optlen);
}
-int Socket::close(bool shutdown)
-{
- if (!_socket) {
- return 0;
- }
-
- int err = _iface->socket_close(_socket, shutdown);
- if (!err) {
- void *socket = _socket;
- _socket = 0;
- _iface->socket_destroy(socket);
- }
-
- return err;
-}
-
void Socket::thunk(void *p)
{
FunctionPointer *fptr = (FunctionPointer *)p;