wangzhengquan
2020-07-27 554529bb69cd610e83db2c9a80b4f36f5225d80f
src/socket/shm_socket.c
@@ -23,6 +23,7 @@
  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;
@@ -46,6 +47,12 @@
  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) {
@@ -60,7 +67,7 @@
    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);
    }
  }
@@ -144,7 +151,7 @@
    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);
    }
  }
@@ -243,7 +250,8 @@
    } 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);
      }
    }
@@ -299,7 +307,8 @@
    } 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);
      }
    }