/** * Send data to the partner. * The return is the number of bytes actually transmitted which may also be * 0 to indicate no bytes sent or -1 to indicate an error. For the ESP8266 implementation we * will return 0 if the socket is not connected or we are in the `SOCKET_STATE_TRANSMITTING` * state. */ int net_ESP8266_BOARD_send( JsNetwork *net, //!< The Network we are going to use to create the socket. int sckt, //!< The socket over which we will send data. const void *buf, //!< The buffer containing the data to be sent. size_t len //!< The length of data in the buffer to send. ) { //DBG("%s:send\n", DBG_LIB); struct socketData *pSocketData = getSocketData(sckt); assert(pSocketData->state != SOCKET_STATE_UNUSED); // If the socket is in error or it is closing return -1 switch (pSocketData->state) { case SOCKET_STATE_CLOSED: case SOCKET_STATE_DISCONNECTING: return pSocketData->errorCode != 0 ? pSocketData->errorCode : SOCKET_ERR_CLOSED; case SOCKET_STATE_ABORTING: return pSocketData->errorCode; case SOCKET_STATE_TO_ABORT: espconn_abort(pSocketData->pEspconn); return pSocketData->errorCode; default: break; } // Unless we are in the idle state, we can't send more shtuff if (pSocketData->state != SOCKET_STATE_IDLE) { return 0; } // Log the content of the data we are sending. //esp8266_board_writeString(buf, len); //os_printf("\n"); // Copy the data to be sent into a transmit buffer we hand off to espconn assert(pSocketData->currentTx == NULL); pSocketData->currentTx = (uint8_t *)os_malloc(len); if (pSocketData->currentTx == NULL) { DBG("%s: Out of memory sending %d on socket %d\n", DBG_LIB, len, sckt); setSocketInError(pSocketData, ESPCONN_MEM); espconn_abort(pSocketData->pEspconn); pSocketData->state = SOCKET_STATE_ABORTING; return pSocketData->errorCode; } memcpy(pSocketData->currentTx, buf, len); // Send the data over the ESP8266 SDK. int rc = espconn_send(pSocketData->pEspconn, pSocketData->currentTx, len); if (rc < 0) { setSocketInError(pSocketData, rc); os_free(pSocketData->currentTx); pSocketData->currentTx = NULL; espconn_abort(pSocketData->pEspconn); pSocketData->state = SOCKET_STATE_ABORTING; return rc; } pSocketData->state = SOCKET_STATE_TRANSMITTING; //DBG("%s: socket %d JS send %d\n", DBG_LIB, sckt, len); return len; }
/*! ** @brief Receive data from an Xsocket ** ** Xrecv() retrieves data from a connected Xsocket of type XSOCK_STREAM. ** sockfd must have previously been connected via Xaccept() or ** Xconnect(). ** ** Xrecv() does not currently have a non-blocking mode, and will block ** until a data is available on sockfd. However, the standard socket API ** calls select and poll may be used with the Xsocket. Either function ** will deliver a readable event when a new connection is attempted and ** you may then call Xrecv() to get the data. ** ** NOTE: in cases where more data is received than specified by the caller, ** the excess data will be stored at the API level. Subsequent Xrecv calls ** return the stored data until it is drained, and will then resume requesting ** data from the transport. ** ** @param sockfd The socket to receive with ** @param rbuf where to put the received data ** @param len maximum amount of data to receive. the amount of data ** returned may be less than len bytes. ** @param flags (This is not currently used but is kept to be compatible ** with the standard sendto socket call). ** ** @returns the number of bytes received, which may be less than the number ** requested by the caller ** @returns -1 on failure with errno set to an error compatible with the standard ** recv call. */ int Xrecv(int sockfd, void *rbuf, size_t len, int flags) { int numbytes; char UDPbuf[MAXBUFLEN]; if (flags) { errno = EOPNOTSUPP; return -1; } if (len == 0) return 0; if (!rbuf) { LOG("buffer pointer is null!\n"); errno = EFAULT; return -1; } if (validateSocket(sockfd, XSOCK_STREAM, EOPNOTSUPP) < 0) { LOGF("Socket %d must be a stream socket", sockfd); return -1; } if (!isConnected(sockfd)) { LOGF("Socket %d is not connected", sockfd); errno = ENOTCONN; return -1; } // see if we have bytes leftover from a previous Xrecv call if ((numbytes = getSocketData(sockfd, (char *)rbuf, len)) > 0) return numbytes; if ((numbytes = click_reply(sockfd, UDPbuf, sizeof(UDPbuf))) < 0) { LOGF("Error retrieving recv data from Click: %s", strerror(errno)); return -1; } std::string str(UDPbuf, numbytes); xia::XSocketMsg xsm; xsm.ParseFromString(str); xia::X_Recv_Msg *msg = xsm.mutable_x_recv(); unsigned paylen = msg->payload().size(); const char *payload = msg->payload().c_str(); if (paylen <= len) memcpy(rbuf, payload, paylen); else { // we got back more data than the caller requested // stash the extra away for subsequent Xrecv calls memcpy(rbuf, payload, len); paylen -= len; setSocketData(sockfd, payload + len, paylen); paylen = len; } return paylen; }
/** * Release the socket and return it to the free pool. */ static void releaseSocket( int socketId //!< The socket id of the socket to be released. ) { os_printf("> releaseSocket: %d\n", socketId); esp8266_dumpSocket(socketId); struct socketData *pSocketData = getSocketData(socketId); assert(pSocketData->state != SOCKET_STATE_UNUSED); if (memoryBuffer_getSize(&pSocketData->txMemoryBuffer) > 0) { os_printf(" - Oh oh ... attempt to close socket while the TX memoryBuffer is not empty!\n"); } if (pSocketData->rxBuf != NULL || pSocketData->rxBufLen != 0) { os_printf(" - Oh oh ... attempt to close socket while the rxBuffer is not empty!\n"); } // If this socket is not an incoming socket that means that the espconn structure was created // by us and we should release the storage we allocated. if (pSocketData->creationType != SOCKET_CREATED_INBOUND) { os_free(pSocketData->pEspconn->proto.tcp); pSocketData->pEspconn->proto.tcp = NULL; os_free(pSocketData->pEspconn); pSocketData->pEspconn = NULL; } resetSocketByData(pSocketData); os_printf("< releaseSocket\n"); }
/** * Perform an actual closure of the socket by calling the ESP8266 disconnect API. * This is broken out into its own function because this can happen in * a number of possible places. */ static void doClose( int socketId //!< The socket id to be closed. ) { // If the socket is NOT in state closing then ask espconn_disconnect to close // the socket and set the state to be closing. // If the socket IS in state closing, then we are ready to release. struct socketData *pSocketData = getSocketData(socketId); if (pSocketData->state != SOCKET_STATE_CLOSING) { int rc = espconn_disconnect(pSocketData->pEspconn); pSocketData->state = SOCKET_STATE_CLOSING; if (rc != 0) { os_printf("espconn_disconnect: rc=%d\n", rc); setSocketInError(socketId, "espconn_disconnect", rc); } } // Our existing state on entry was SOCKET_STATE_CLOSING which means that we got here // because we were previously flagged as closing. else { releaseSocket(socketId); } }
/** * Close a socket. */ void net_ESP8266_BOARD_closeSocket( JsNetwork *net, //!< The Network we are going to use to create the socket. int socketId //!< The socket to be closed. ) { os_printf("> net_ESP8266_BOARD_closeSocket, socket=%d\n", socketId); struct socketData *pSocketData = getSocketData(socketId); assert(pSocketData != NULL); assert(pSocketData->state != SOCKET_STATE_UNUSED); // Shouldn't be closing an unused socket. dumpEspConn(pSocketData->pEspconn); esp8266_dumpSocket(socketId); // How we close the socket is a function of what kind of socket it is. if (pSocketData->creationType == SOCKET_CREATED_SERVER) { int rc = espconn_delete(pSocketData->pEspconn); if (rc != 0) { os_printf("espconn_delete: rc=%d\n", rc); } } // End this is a server socket else { if (pSocketData->state == SOCKET_STATE_IDLE || pSocketData->state == SOCKET_STATE_CLOSING) { doClose(socketId); } else { pSocketData->shouldClose = true; } } // End this is a client socket }
/** * Set the given socket as being in error supplying a message and a code. * The socket state is placed in `SOCKET_STATE_ERROR`. */ static void setSocketInError( int socketId, //!< The socket id that is being flagged as in error. char *msg, //!< A message to associate with the error. int code //!< A low level error code. ) { struct socketData *pSocketData = getSocketData(socketId); pSocketData->state = SOCKET_STATE_ERROR; pSocketData->errorMsg = msg; pSocketData->errorCode = code; }
SSLSocket::SSLSocket(int sockfd, int type, const req::ptr<StreamContext>& ctx, const char *address /* = NULL */, int port /* = 0 */) : Socket(std::make_shared<SSLSocketData>(port, type), sockfd, type, address, port), m_data(static_cast<SSLSocketData*>(getSocketData())) { if (!ctx) { return; } this->setStreamContext(ctx); this->m_context = ctx->getOptions()[s_ssl].toArray(); }
void SocketComponent::executeEvent(GameEvent* event) { switch (event->id()) { case GameEvent::E_SEND_SOCKET_DATA: { sendSocketData(static_cast<const char*>(event->data())); } break; case GameEvent::E_GET_SOCKET_DATA: { getSocketData(static_cast<const char**>(event->data())); } break; case GameEvent::E_GET_SOCKET_NEWEST_MSG: { getSocketData(static_cast<const char**>(event->data()), true); } break; } }
/** * Send data to the partner. * The return is the number of bytes actually transmitted which may also be * 0 to indicate no bytes sent or -1 to indicate an error. For the ESP8266 implementation we * will return 0 if the socket is not connected or we are in the `SOCKET_STATE_TRANSMITTING` * state. */ int net_ESP8266_BOARD_send( JsNetwork *net, //!< The Network we are going to use to create the socket. int sckt, //!< The socket over which we will send data. const void *buf, //!< The buffer containing the data to be sent. size_t len //!< The length of data in the buffer to send. ) { os_printf("> net_ESP8266_BOARD_send: Request to send data to socket %d of size %d: ", sckt, len); struct socketData *pSocketData = getSocketData(sckt); assert(pSocketData->state != SOCKET_STATE_UNUSED); // If we are not connected, then we can't currently send data. if (pSocketData->isConnected == false) { os_printf(" - Not connected\n"); return 0; } // If we are currently sending data, we can't send more. if (pSocketData->state == SOCKET_STATE_TRANSMITTING) { os_printf(" - Currently transmitting\n"); return 0; } // Log the content of the data we are sening. esp8266_board_writeString(buf, len); os_printf("\n"); assert(pSocketData->state == SOCKET_STATE_IDLE); pSocketData->state = SOCKET_STATE_TRANSMITTING; // Copy the data that was passed to us to a private area. We do this because we must not // assume that the data passed in will be available after this function returns. It may have // been passed in on the stack. assert(pSocketData->currentTx == NULL); pSocketData->currentTx = (uint8_t *)os_malloc(len); memcpy(pSocketData->currentTx, buf, len); // Send the data over the ESP8266 SDK. int rc = espconn_send(pSocketData->pEspconn, pSocketData->currentTx, len); if (rc < 0) { setSocketInError(sckt, "espconn_send", rc); os_free(pSocketData->currentTx); pSocketData->currentTx = NULL; return -1; } esp8266_dumpSocket(sckt); os_printf("< net_ESP8266_BOARD_send\n"); return len; }
/** * Receive data from the network device. * Returns the number of bytes received which may be 0 and -1 if there was an error. */ int net_ESP8266_BOARD_recv( JsNetwork *net, //!< The Network we are going to use to create the socket. int sckt, //!< The socket from which we are to receive data. void *buf, //!< The storage buffer into which we will receive data. size_t len //!< The length of the buffer. ) { struct socketData *pSocketData = getSocketData(sckt); assert(pSocketData->state != SOCKET_STATE_UNUSED); // If there is no data in the receive buffer, then all we need do is return // 0 bytes as the length of data moved. if (pSocketData->rxBufLen == 0) { if (pSocketData->state == SOCKET_STATE_CLOSING) { return -1; } return 0; } // If the receive buffer contains data and is it is able to fit in the buffer // passed into us then we can copy all the data and the receive buffer will be clear. if (pSocketData->rxBufLen <= len) { memcpy(buf, pSocketData->rxBuf, pSocketData->rxBufLen); int retLen = pSocketData->rxBufLen; os_free(pSocketData->rxBuf); pSocketData->rxBufLen = 0; pSocketData->rxBuf = NULL; return retLen; } // If we are here, then we have more data in the receive buffer than is available // to be returned in this request for data. So we have to copy the amount of data // that is allowed to be returned and then strip that from the beginning of the // receive buffer. // First we copy the data we are going to return. memcpy(buf, pSocketData->rxBuf, len); // Next we allocate a new buffer and copy in the data we are not returning. uint8 *pNewBuf = (uint8 *)os_malloc(pSocketData->rxBufLen-len); memcpy(pNewBuf, pSocketData->rxBuf + len, pSocketData->rxBufLen-len); // Now we juggle pointers and release the original RX buffer now that we have a new // one. It is likely that this algorithm can be significantly improved since there // is a period of time where we might actuall have TWO copies of the data. uint8 *pTemp = pSocketData->rxBuf; pSocketData->rxBuf = pNewBuf; pSocketData->rxBufLen = pSocketData->rxBufLen-len; os_free(pTemp); return len; }
/** * Callback function registered to the ESP8266 environment that is * invoked when a new inbound connection has been formed. * A new connection * can occur when the ESP8266 makes a call out to a partner (in that * case the ESP8266 is acting as a client) or a new connection can * occur when a partner calls into a listening ESP8266. In that case * the ESP8266 is acting as a server. */ static void esp8266_callback_connectCB_inbound( void *arg //!< ) { os_printf(">> connectCB_inbound\n"); struct espconn *pEspconn = (struct espconn *)arg; assert(pEspconn != NULL); espconn_regist_disconcb(pEspconn, esp8266_callback_disconnectCB); espconn_regist_reconcb(pEspconn, esp8266_callback_reconnectCB); espconn_regist_sentcb(pEspconn, esp8266_callback_sentCB); espconn_regist_recvcb(pEspconn, esp8266_callback_recvCB); espconn_regist_write_finish(pEspconn, esp8266_callback_writeFinishedCB); dumpEspConn(pEspconn); int inboundSocket = getServerSocketByLocalPort(pEspconn->proto.tcp->local_port); assert(inboundSocket != -1); struct socketData *pSocketData = getSocketData(inboundSocket); assert(pSocketData != NULL); esp8266_dumpSocket(pSocketData->socketId); os_printf("** new client has connected to us **\n"); if ((pSocketData->acceptedSocketsHead + 1) % MAX_ACCEPTED_SOCKETS == pSocketData->acceptedSocketsTail) { os_printf("WARNING!! - Discarding inbound client because we have too many accepted clients.\n"); os_printf("<< connectCB_inbound\n"); return; } struct socketData *pClientSocketData = allocateNewSocket(); if (pClientSocketData == NULL) { os_printf("!!! Ran out of sockets !!!\n"); return; } assert(pClientSocketData != NULL); pClientSocketData->pEspconn = pEspconn; pClientSocketData->pEspconn->reverse = pClientSocketData; pClientSocketData->creationType = SOCKET_CREATED_INBOUND; pClientSocketData->isConnected = true; pClientSocketData->state = SOCKET_STATE_IDLE; pSocketData->acceptedSockets[pSocketData->acceptedSocketsHead] = pClientSocketData->socketId; pSocketData->acceptedSocketsHead = (pSocketData->acceptedSocketsHead + 1) % MAX_ACCEPTED_SOCKETS; os_printf("<< connectCB_inbound\n"); }
/** * Close a socket. * This gets called in two situations: when the user requests the close of a socket and as * an acknowledgment after we signal the socket library that a connection has closed by * returning <0 to a send or recv call. */ void net_ESP8266_BOARD_closeSocket( JsNetwork *net, //!< The Network we are going to use to create the socket. int socketId //!< The socket to be closed. ) { struct socketData *pSocketData = getSocketData(socketId); assert(pSocketData != NULL); // We had better have found a socket to be closed. assert(pSocketData->state != SOCKET_STATE_UNUSED); // Shouldn't be closing an unused socket. if (pSocketData->state == SOCKET_STATE_CLOSED) { // In these states we have already freed the espconn structures, so all that's left is to // free the socket structure //DBG("%s: socket %d close acknowledged\n", DBG_LIB, pSocketData->socketId); releaseSocket(pSocketData); } else { // Looks like this is the user telling us to close a connection, let's do it. DBG("%s: socket %d to be closed\n", DBG_LIB, pSocketData->socketId); doClose(pSocketData); } }
/** * Determine if there is a new client connection on the server socket. * This function is called to poll to see if the serverSckt has a new * accepted connection (socket) and, if it does, return it else return -1 to indicate * that there was no new accepted socket. */ int net_ESP8266_BOARD_accept( JsNetwork *net, //!< The Network we are going to use to create the socket. int serverSckt //!< The socket that we are checking to see if there is a new client connection. ) { //os_printf("> net_ESP8266_BOARD_accept\n"); struct socketData *pSocketData = getSocketData(serverSckt); assert(pSocketData->state != SOCKET_STATE_UNUSED); assert(pSocketData->creationType == SOCKET_CREATED_SERVER); // If the list is empty, return. if (pSocketData->acceptedSocketsHead == pSocketData->acceptedSocketsTail) { // Return -1 if there is no new client socket for this server. return -1; } // Return the 1st socket id that is in the list of accepted sockets. We also update the // list to indicate that it has been read. int acceptedSocketId = pSocketData->acceptedSockets[pSocketData->acceptedSocketsTail]; pSocketData->acceptedSocketsTail = (pSocketData->acceptedSocketsTail + 1) % MAX_ACCEPTED_SOCKETS; os_printf("> net_ESP8266_BOARD_accept: Accepted a new socket, socketId=%d\n", acceptedSocketId); return acceptedSocketId; }
/** * Determine if there is a new client connection on the server socket. * This function is called to poll to see if the serverSckt has a new * accepted connection (socket) and, if it does, return it else return -1 to indicate * that there was no new accepted socket. */ int net_ESP8266_BOARD_accept( JsNetwork *net, //!< The Network we are going to use to create the socket. int serverSckt //!< The socket that we are checking to see if there is a new client connection. ) { struct socketData *pSocketData = getSocketData(serverSckt); assert(pSocketData->state != SOCKET_STATE_UNUSED); assert(pSocketData->creationType == SOCKET_CREATED_SERVER); // iterate through all sockets and see whether there is one in the UNACCEPTED state that is for // the server socket's local port. uint16_t serverPort = pSocketData->pEspconn->proto.tcp->local_port; for (uint8_t i=0; i<MAX_SOCKETS; i++) { if (socketArray[i].state == SOCKET_STATE_UNACCEPTED && socketArray[i].pEspconn != NULL && socketArray[i].pEspconn->proto.tcp->local_port == serverPort) { DBG("%s: Accepted socket %d\n", DBG_LIB, socketArray[i].socketId); socketArray[i].state = SOCKET_STATE_IDLE; return socketArray[i].socketId; } } return -1; }
/** * Write the details of a socket to the debug log. * The data associated with the socket is dumped to the debug log. */ void esp8266_dumpSocket( int socketId //!< The ID of the socket data structure to be logged. ) { struct socketData *pSocketData = getSocketData(socketId); esp8266_dumpSocketData(pSocketData); }
/** * Receive data from the network device. * Returns the number of bytes received which may be 0 and <0 if there was an error. */ int net_ESP8266_BOARD_recv( JsNetwork *net, //!< The Network we are going to use to create the socket. int sckt, //!< The socket from which we are to receive data. void *buf, //!< The storage buffer into which we will receive data. size_t len //!< The length of the buffer. ) { //DBG("%s:recv\n", DBG_LIB); struct socketData *pSocketData = getSocketData(sckt); assert(pSocketData); assert(pSocketData->state != SOCKET_STATE_UNUSED); // handle socket that needs aborting if (pSocketData->state == SOCKET_STATE_TO_ABORT) { espconn_abort(pSocketData->pEspconn); return pSocketData->errorCode; } // If there is no data in the receive buffer, then all we need do is return // 0 bytes as the length of data moved or -1 if the socket is actually closed. if (pSocketData->rxBufQ == NULL) { switch (pSocketData->state) { case SOCKET_STATE_CLOSED: return pSocketData->errorCode != 0 ? pSocketData->errorCode : SOCKET_ERR_CLOSED; case SOCKET_STATE_DISCONNECTING: case SOCKET_STATE_ABORTING: return pSocketData->errorCode; case SOCKET_STATE_HOST_RESOLVING: case SOCKET_STATE_CONNECTING: return SOCKET_ERR_NO_CONN; default: return 0; // we just have no data } } PktBuf *rxBuf = pSocketData->rxBufQ; // If the receive buffer is able to completely fit in the buffer // passed into us then we can copy all the data and the receive buffer will be clear. if (rxBuf->filled <= len) { os_memcpy(buf, rxBuf->data, rxBuf->filled); int retLen = rxBuf->filled; pSocketData->rxBufQ = PktBuf_ShiftFree(rxBuf); // if we now have exactly one buffer enqueued we need to re-enable the flood if (pSocketData->rxBufQ != NULL && pSocketData->rxBufQ->next == NULL) espconn_recv_unhold(pSocketData->pEspconn); //DBG("%s: socket %d JS recv %d\n", DBG_LIB, sckt, retLen); return retLen; } // If we are here, then we have more data in the receive buffer than is available // to be returned in this request for data. So we have to copy the amount of data // that is allowed to be returned and then strip that from the beginning of the // receive buffer. // First we copy the data we are going to return. os_memcpy(buf, rxBuf->data, len); // Next we shift up the remaining data uint16_t newLen = rxBuf->filled - len; os_memmove(rxBuf->data, rxBuf->data + len, newLen); rxBuf->filled = newLen; //DBG("%s: socket %d JS recv %d\n", DBG_LIB, sckt, len); return len; }
SSLSocket::SSLSocket() : Socket(std::make_shared<SSLSocketData>()), m_data(static_cast<SSLSocketData*>(getSocketData())) {}
SSLSocket::SSLSocket(std::shared_ptr<SSLSocketData> data) : Socket(data), m_data(static_cast<SSLSocketData*>(getSocketData())) {}
/** * Write the details of a socket to the debug log. * The data associated with the socket is dumped to the debug log. */ void esp8266_dumpSocket( int socketId //!< The ID of the socket data structure to be logged. ) { struct socketData *pSocketData = getSocketData(socketId); LOG("Dump of socket=%d\n", socketId); LOG(" - isConnected=%d", pSocketData->isConnected); char *creationTypeMsg; switch(pSocketData->creationType) { case SOCKET_CREATED_NONE: creationTypeMsg = "SOCKET_CREATED_NONE"; break; case SOCKET_CREATED_INBOUND: creationTypeMsg = "SOCKET_CREATED_INBOUND"; break; case SOCKET_CREATED_OUTBOUND: creationTypeMsg = "SOCKET_CREATED_OUTBOUND"; break; case SOCKET_CREATED_SERVER: creationTypeMsg = "SOCKET_CREATED_SERVER"; break; } LOG(", creationType=%s", creationTypeMsg); LOG(", acceptedSockets=["); int s=pSocketData->acceptedSocketsTail; while(s != pSocketData->acceptedSocketsHead) { LOG(" %d", pSocketData->acceptedSockets[s]); s = (s+1)%MAX_ACCEPTED_SOCKETS; } LOG("]"); LOG(", rxBufLen=%d", pSocketData->rxBufLen); LOG(", tx length=%d", memoryBuffer_getSize(&(pSocketData->txMemoryBuffer))); LOG(", currentTx=0x%d", (int)pSocketData->currentTx); char *stateMsg; switch(pSocketData->state) { case SOCKET_STATE_CLOSING: stateMsg = "SOCKET_STATE_CLOSING"; break; case SOCKET_STATE_CONNECTING: stateMsg = "SOCKET_STATE_CONNECTING"; break; case SOCKET_STATE_ERROR: stateMsg = "SOCKET_STATE_ERROR"; break; case SOCKET_STATE_IDLE: stateMsg = "SOCKET_STATE_IDLE"; break; case SOCKET_STATE_TRANSMITTING: stateMsg = "SOCKET_STATE_TRANSMITTING"; break; case SOCKET_STATE_HOST_RESOLVING: stateMsg = "SOCKET_STATE_HOST_RESOLVING"; break; case SOCKET_STATE_UNUSED: stateMsg = "SOCKET_STATE_UNUSED"; break; default: stateMsg = "Unexpected state!!"; break; } LOG(", state=%s", stateMsg); LOG(", errorCode=%d", pSocketData->errorCode); // Print the errorMsg if it has anything to say if (pSocketData->errorMsg != NULL && strlen(pSocketData->errorMsg) > 0) { LOG(", errorMsg=\"%s\"", pSocketData->errorMsg); } LOG("\n"); }
/** * Reset the socket to its clean and unused state. * The socket is found by its socket id. */ static void resetSocketById( int sckt //!< The socket id to be reset. ) { struct socketData *pSocketData = getSocketData(sckt); resetSocketByData(pSocketData); }
SSLSocket::SSLSocket(int sockfd, int type, const char *address /* = NULL */, int port /* = 0 */) : Socket(std::make_shared<SSLSocketData>(), sockfd, type, address, port), m_data(static_cast<SSLSocketData*>(getSocketData())) {}
SSLSocket::SSLSocket(bool nonblocking /* = true*/) : Socket(std::make_shared<SSLSocketData>(nonblocking)), m_data(static_cast<SSLSocketData*>(getSocketData())) {}