| | |
| | | |
| | | shm_socket_t *shm_open_socket(shm_socket_type_t socket_type) { |
| | | |
| | | logger->debug("shm_open_socket\n"); |
| | | shm_socket_t *socket = (shm_socket_t *)calloc(1, sizeof(shm_socket_t)); |
| | | socket->socket_type = socket_type; |
| | | socket->key = -1; |
| | |
| | | socket->dispatch_thread = 0; |
| | | socket->status = SHM_CONN_CLOSED; |
| | | socket->mutex = SemUtil::get(IPC_PRIVATE, 1); |
| | | logger->debug("shm_open_socket\n"); |
| | | |
| | | return socket; |
| | | } |
| | | |
| | | static int _shm_close_socket(shm_socket_t *socket) { |
| | | 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; |
| | | } |
| | | |
| | | int shm_close_socket(shm_socket_t *socket) { |
| | | // int shm_close_socket(shm_socket_t *socket) { |
| | | |
| | | // _destrory_tmp_recv_socket_((shm_socket_t *)pthread_getspecific(_tmp_recv_socket_key_)); |
| | | // // _destrory_tmp_recv_socket_((shm_socket_t *)pthread_getspecific(_tmp_recv_socket_key_)); |
| | | |
| | | return _shm_close_socket(socket);; |
| | | } |
| | | // return shm_close_socket(socket);; |
| | | // } |
| | | |
| | | int shm_socket_bind(shm_socket_t *socket, int key) { |
| | | socket->key = key; |
| | |
| | | "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; |
| | |
| | | } |
| | | |
| | | if (rv) { |
| | | void *_buf = malloc(src.size); |
| | | memcpy(_buf, src.buf, src.size); |
| | | *buf = _buf; |
| | | *size = src.size; |
| | | *key = src.key; |
| | | if(buf != NULL) { |
| | | void *_buf = malloc(src.size); |
| | | memcpy(_buf, src.buf, src.size); |
| | | *buf = _buf; |
| | | } |
| | | |
| | | if(size != NULL) |
| | | *size = src.size; |
| | | |
| | | if(key != NULL) |
| | | *key = src.key; |
| | | |
| | | mm_free(src.buf); |
| | | // printf("shm_recvfrom pop after\n"); |
| | | return 0; |
| | |
| | | int rv; |
| | | if(tmp_socket == NULL) |
| | | return; |
| | | |
| | | logger->debug("%d destroy tmp socket\n", pthread_self()); |
| | | _shm_close_socket((shm_socket_t *)tmp_socket); |
| | | shm_close_socket((shm_socket_t *)tmp_socket); |
| | | rv = pthread_setspecific(_tmp_recv_socket_key_, NULL); |
| | | if ( rv != 0) { |
| | | logger->error(rv, "shm_sendandrecv : pthread_setspecific"); |
| | | exit(1); |
| | | logger->error(rv, "shm_sendandrecv : pthread_setspecific"); |
| | | exit(1); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | |
| | | |
| | | int shm_sendandrecv(shm_socket_t *socket, const void *send_buf, |
| | | int shm_sendandrecv_safe(shm_socket_t *socket, const void *send_buf, |
| | | const int send_size, const int send_key, void **recv_buf, |
| | | int *recv_size, struct timespec *timeout, int flags) { |
| | | int recv_key; |
| | |
| | | return -1; |
| | | } |
| | | |
| | | int shm_sendandrecv(shm_socket_t *socket, const void *send_buf, |
| | | const int send_size, const int send_key, void **recv_buf, |
| | | int *recv_size, struct timespec *timeout, int flags) { |
| | | return shm_sendandrecv_unsafe(socket, send_buf, send_size, send_key,recv_buf, recv_size, timeout, flags); |
| | | } |
| | | |
| | | |
| | | // ============================================================================================================ |
| | | |
| | | /** |