| | |
| | | static inline int _shm_socket_check_key(shm_socket_t *socket) { |
| | | void *tmp_ptr = mm_get_by_key(socket->key); |
| | | if (tmp_ptr!= NULL && tmp_ptr != (void *)1 && !socket->force_bind ) { |
| | | logger->error("key %d has already been in used!", socket->key); |
| | | bus_errno = EBUS_KEY_INUSED; |
| | | logger->error("%s. key = %d ", bus_strerror(bus_errno), socket->key); |
| | | return 0; |
| | | } |
| | | return 1; |
| | |
| | | int shm_close_socket(shm_socket_t *socket) { |
| | | |
| | | int ret; |
| | | |
| | | |
| | | logger->debug("shm_close_socket\n"); |
| | | switch (socket->socket_type) { |
| | | case SHM_SOCKET_STREAM: |
| | | ret = _shm_close_stream_socket(socket, true); |
| | |
| | | } |
| | | free(socket); |
| | | SemUtil::remove(socket->mutex); |
| | | logger->debug("shm_close_socket\n"); |
| | | return ret; |
| | | } |
| | | |
| | |
| | | } else { |
| | | |
| | | if(!_shm_socket_check_key(socket)) { |
| | | return -1; |
| | | bus_errno = EBUS_KEY_INUSED; |
| | | return EBUS_KEY_INUSED; |
| | | } |
| | | } |
| | | |
| | |
| | | socket->key = hashtable_alloc_key(hashtable); |
| | | } else { |
| | | if(!_shm_socket_check_key(socket)) { |
| | | return -1; |
| | | bus_errno = EBUS_KEY_INUSED; |
| | | return EBUS_KEY_INUSED; |
| | | } |
| | | } |
| | | |
| | |
| | | "SHM_SOCKET_STREAM socket"); |
| | | exit(1); |
| | | } |
| | | // hashtable_t *hashtable = mm_get_hashtable(); |
| | | // if(socket->remoteQueue == NULL) { |
| | | // err_msg(errno, "当前客户端无连接!"); |
| | | // return -1; |
| | | // } |
| | | hashtable_t *hashtable = mm_get_hashtable(); |
| | | if(socket->remoteQueue == NULL) { |
| | | err_msg(errno, "当前客户端无连接!"); |
| | | return -1; |
| | | } |
| | | shm_msg_t dest; |
| | | dest.type = SHM_COMMON_MSG; |
| | | dest.key = socket->key; |
| | |
| | | } else { |
| | | |
| | | if(!_shm_socket_check_key(socket)) { |
| | | return -1; |
| | | bus_errno = EBUS_KEY_INUSED; |
| | | return EBUS_KEY_INUSED; |
| | | } |
| | | |
| | | } |
| | |
| | | } else { |
| | | |
| | | if(!_shm_socket_check_key(socket)) { |
| | | return -1; |
| | | bus_errno = EBUS_KEY_INUSED; |
| | | return EBUS_KEY_INUSED; |
| | | } |
| | | } |
| | | |
| | |
| | | return shm_sendandrecv_unsafe(socket, send_buf, send_size, send_key,recv_buf, recv_size, timeout, flags); |
| | | } |
| | | |
| | | |
| | | // ============================================================================================================ |
| | | |
| | | /** |