/*== Add new socket ==*/ static int addSocket(tnet_fd_t fd, tnet_socket_type_t type, tnet_transport_t *transport, int take_ownership, int is_client) { transport_context_t *context = transport?transport->context:0; if(context){ transport_socket_t *sock = tsk_calloc(1, sizeof(transport_socket_t)); sock->fd = fd; sock->type = type; sock->owner = take_ownership ? 1 : 0; if(TNET_SOCKET_TYPE_IS_TLS(sock->type)){ sock->tlshandle = tnet_sockfd_set_tlsfiles(sock->fd, is_client, transport->tls.ca, transport->tls.pvk, transport->tls.pbk); } tsk_safeobj_lock(context); context->events[context->count] = WSACreateEvent(); context->sockets[context->count] = sock; context->count++; tsk_safeobj_unlock(context); return 0; } else{ TSK_DEBUG_ERROR("Context is Null."); return -1; } }
int tnet_socket_set_tlsfiles(tnet_socket_tls_t* socket, int isClient, const char* tlsfile_ca, const char* tlsfile_pvk, const char* tlsfile_pbk) { if(socket){ return -1; } if(!TNET_SOCKET_TYPE_IS_TLS(socket->type)){ TSK_DEBUG_ERROR("Not TLS socket."); return -2; } if(socket->tlshandle){ TSK_DEBUG_ERROR("TLS files already set."); return -3; } if((socket->tlshandle = tnet_sockfd_set_tlsfiles(socket->fd, isClient, tlsfile_ca, tlsfile_pvk, tlsfile_pbk))){ return 0; } else{ return -4; } }