| | |
| | | shm_socket_t *socket = (shm_socket_t *)calloc(1, sizeof(shm_socket_t)); |
| | | socket->socket_type = socket_type; |
| | | socket->port = -1; |
| | | socket->force_bind = false; |
| | | socket->dispatch_thread = 0; |
| | | socket->status = SHM_CONN_CLOSED; |
| | | |
| | |
| | | return 0; |
| | | } |
| | | |
| | | int shm_socket_force_bind(shm_socket_t *socket, int port) { |
| | | socket->force_bind = true; |
| | | socket->port = port; |
| | | return 0; |
| | | } |
| | | |
| | | int shm_listen(shm_socket_t *socket) { |
| | | |
| | | if (socket->socket_type != SHM_SOCKET_STREAM) { |
| | |
| | | socket->port = port; |
| | | } else { |
| | | |
| | | if (hashtable_get(hashtable, socket->port) != NULL) { |
| | | if (hashtable_get(hashtable, socket->port) != NULL && !socket->force_bind) { |
| | | err_exit(0, "key %d has already been in used!", socket->port); |
| | | } |
| | | } |
| | |
| | | socket->port = hashtable_alloc_key(hashtable); |
| | | } else { |
| | | |
| | | if (hashtable_get(hashtable, socket->port) != NULL) { |
| | | if (hashtable_get(hashtable, socket->port) != NULL && !socket->force_bind ) { |
| | | err_exit(0, "key %d has already been in used!", socket->port); |
| | | } |
| | | } |
| | |
| | | } else { |
| | | |
| | | if (hashtable_get(hashtable, socket->port) != NULL) { |
| | | err_exit(0, "key %d has already been in used!", socket->port); |
| | | if(!socket->force_bind) |
| | | err_exit(0, "key %d has already been in used!", socket->port); |
| | | } |
| | | } |
| | | |
| | |
| | | } else { |
| | | |
| | | if (hashtable_get(hashtable, socket->port) != NULL) { |
| | | err_exit(0, "key %d has already been in used!", socket->port); |
| | | if(!socket->force_bind) |
| | | err_exit(0, "key %d has already been in used!", socket->port); |
| | | } |
| | | } |
| | | |