Fix small issues from the review

pull/7192/head
Seppo Takalo 2018-06-19 17:57:56 +03:00
parent 2b60e42756
commit e7cb4752fa
3 changed files with 12 additions and 10 deletions

View File

@ -114,10 +114,10 @@ public:
*/ */
void set_port(uint16_t port); void set_port(uint16_t port);
/** Get the human readable IP address /** Get the human-readable IP address
* *
* Allocates memory for a string and converts binary address to * Allocates memory for a string and converts binary address to
* human readable format. String is freed in the destructor. * human-readable format. String is freed in the destructor.
* *
* @return Null-terminated representation of the IP Address * @return Null-terminated representation of the IP Address
*/ */
@ -153,7 +153,7 @@ public:
*/ */
operator bool() const; operator bool() const;
/** Copy addres from another SocketAddress /** Copy address from another SocketAddress
* *
* @param addr SocketAddress to copy * @param addr SocketAddress to copy
*/ */

View File

@ -249,21 +249,22 @@ TCPSocket *TCPSocket::accept(nsapi_error_t *error)
{ {
_lock.lock(); _lock.lock();
TCPSocket *connection = NULL; TCPSocket *connection = NULL;
nsapi_error_t ret;
_readers++; _readers++;
while (true) { while (true) {
if (!_socket) { if (!_socket) {
*error = NSAPI_ERROR_NO_SOCKET; ret = NSAPI_ERROR_NO_SOCKET;
break; break;
} }
_pending = 0; _pending = 0;
void *socket; void *socket;
SocketAddress address; SocketAddress address;
*error = _stack->socket_accept(_socket, &socket, &address); ret = _stack->socket_accept(_socket, &socket, &address);
if (0 == *error) { if (0 == ret) {
TCPSocket *connection = new TCPSocket(); TCPSocket *connection = new TCPSocket();
connection->_lock.lock(); connection->_lock.lock();
connection->_factory_allocated = true; // Destroy automatically on close() connection->_factory_allocated = true; // Destroy automatically on close()
@ -275,7 +276,7 @@ TCPSocket *TCPSocket::accept(nsapi_error_t *error)
connection->_lock.unlock(); connection->_lock.unlock();
break; break;
} else if ((_timeout == 0) || (*error != NSAPI_ERROR_WOULD_BLOCK)) { } else if ((_timeout == 0) || (ret != NSAPI_ERROR_WOULD_BLOCK)) {
break; break;
} else { } else {
uint32_t flag; uint32_t flag;
@ -288,7 +289,7 @@ TCPSocket *TCPSocket::accept(nsapi_error_t *error)
if (flag & osFlagsError) { if (flag & osFlagsError) {
// Timeout break // Timeout break
*error = NSAPI_ERROR_WOULD_BLOCK; ret = NSAPI_ERROR_WOULD_BLOCK;
break; break;
} }
} }
@ -299,5 +300,8 @@ TCPSocket *TCPSocket::accept(nsapi_error_t *error)
_event_flag.set(FINISHED_FLAG); _event_flag.set(FINISHED_FLAG);
} }
_lock.unlock(); _lock.unlock();
if (error) {
*error = ret;
}
return connection; return connection;
} }

View File

@ -34,8 +34,6 @@ nsapi_protocol_t UDPSocket::get_proto()
nsapi_error_t UDPSocket::connect(const SocketAddress &address) nsapi_error_t UDPSocket::connect(const SocketAddress &address)
{ {
if (!address)
return NSAPI_ERROR_PARAMETER;
_remote_peer = address; _remote_peer = address;
return NSAPI_ERROR_OK; return NSAPI_ERROR_OK;
} }