From aa515539d6b88d5270c7dd435e54471edb7d6749 Mon Sep 17 00:00:00 2001 From: wangzhengquan <wangzhengquan85@126.com> Date: 星期四, 26 十一月 2020 14:26:41 +0800 Subject: [PATCH] udpate --- /dev/null | 77 ------------------- src/socket/shm_stream_mod_socket.h | 77 +++++++++++++++++++ src/socket/shm_stream_mod_socket.c | 48 ++++++------ 3 files changed, 101 insertions(+), 101 deletions(-) diff --git a/src/socket/mod_socket.h b/src/socket/mod_socket.h deleted file mode 100644 index 2fd44cc..0000000 --- a/src/socket/mod_socket.h +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef __MOD_SOCKET_H__ -#define __MOD_SOCKET_H__ - - -#ifdef __cplusplus -extern "C" { -#endif - -enum socket_mod_t -{ - PULL_PUSH = 1, - REQ_REP = 2, - PAIR = 3, - PUB_SUB = 4, - SURVEY = 5, - BUS = 6 - -}; - -/** - * 鍒涘缓socket - * @return socket鍦板潃 -*/ -void *mod_open_socket(int mod); - -/** - * 鍏抽棴socket - * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜 -*/ -int mod_close_socket(void * _socket); - -/** - * 缁戝畾绔彛鍒皊ocket, 濡傛灉涓嶇粦瀹氬垯绯荤粺鑷姩鍒嗛厤涓�涓� - * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜 -*/ -int mod_socket_bind(void * _socket, int port); - - -/** - * 鏈嶅姟绔紑鍚繛鎺ョ洃鍚� - * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜 - */ -int mod_listen(void * _socket); - -/** - * 瀹㈡埛绔彂璧疯繛鎺ヨ姹� - */ -int mod_connect(void * _socket, int port); - -/** - * 鍙戦�佷俊鎭� - * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜 - */ -int mod_send(void * _socket, const void *buf, const int size); - -/** - * 鎺ユ敹淇℃伅 - * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜 -*/ -int mod_recv(void * _socket, void **buf, int *size) ; - -/** - * 閲婃斁瀛樺偍鎺ユ敹淇℃伅鐨刡uf - */ -void mod_free(void *buf); - - -/** - * 鑾峰彇soket绔彛鍙� - */ -int mod_get_socket_port(void * _socket); - -#ifdef __cplusplus -} -#endif - -#endif \ No newline at end of file diff --git a/src/socket/mod_socket.c b/src/socket/shm_stream_mod_socket.c similarity index 69% rename from src/socket/mod_socket.c rename to src/socket/shm_stream_mod_socket.c index b5a686a..ca8c2a1 100644 --- a/src/socket/mod_socket.c +++ b/src/socket/shm_stream_mod_socket.c @@ -1,5 +1,5 @@ #include "usg_common.h" -#include "mod_socket.h" +#include "shm_stream_mod_socket.h" #include "shm_socket.h" #include "shm_allocator.h" #include "mem_pool.h" @@ -16,7 +16,7 @@ shm_socket_t *client_socket; }mod_entry_t; -typedef struct mod_socket_t { +typedef struct shm_stream_mod_socket_t { socket_mod_t mod; shm_socket_t *shm_socket; shm_socket_t *client_socket; @@ -26,13 +26,13 @@ int items; -} mod_socket_t; +} shm_stream_mod_socket_t; /** * */ -void *mod_open_socket(int mod) { - mod_socket_t *socket = (mod_socket_t *)malloc(sizeof(mod_socket_t)); +void *shm_stream_mod_socket_open(int mod) { + shm_stream_mod_socket_t *socket = (shm_stream_mod_socket_t *)malloc(sizeof(shm_stream_mod_socket_t)); socket->shm_socket=shm_open_socket(SHM_SOCKET_STREAM); socket->is_server = 0; socket->mod = (socket_mod_t)mod; @@ -47,8 +47,8 @@ -int mod_close_socket(void * _socket){ - mod_socket_t * socket = (mod_socket_t *) _socket; +int shm_stream_mod_socket_close(void * _socket){ + shm_stream_mod_socket_t * socket = (shm_stream_mod_socket_t *) _socket; if (socket->mod == REQ_REP) { SemUtil::remove(socket->slots); @@ -63,14 +63,14 @@ -int mod_socket_bind(void * _socket, int port){ - mod_socket_t * socket = (mod_socket_t *) _socket; +int shm_stream_mod_socket_bind(void * _socket, int port){ + shm_stream_mod_socket_t * socket = (shm_stream_mod_socket_t *) _socket; return shm_socket_bind(socket->shm_socket, port); } void * run_server_recv_client_msg(void *_socket) { pthread_detach(pthread_self()); - mod_socket_t * socket = (mod_socket_t *) _socket; + shm_stream_mod_socket_t * socket = (shm_stream_mod_socket_t *) _socket; shm_socket_t * client_socket = socket->client_socket; mod_entry_t entry; @@ -88,23 +88,23 @@ } void *run_accept_connection(void * _socket) { - mod_socket_t * socket = (mod_socket_t *) _socket; + shm_stream_mod_socket_t * socket = (shm_stream_mod_socket_t *) _socket; shm_socket_t *client_socket; pthread_t tid; while(socket->shm_socket->status == SHM_CONN_LISTEN) { //鎺ュ彈瀹㈡埛绔殑杩炴帴璇锋眰 client_socket = shm_accept(socket->shm_socket); - mod_socket_t *arg = (mod_socket_t *)malloc(sizeof(mod_socket_t)); - memcpy(arg, _socket, sizeof(mod_socket_t)); + shm_stream_mod_socket_t *arg = (shm_stream_mod_socket_t *)malloc(sizeof(shm_stream_mod_socket_t)); + memcpy(arg, _socket, sizeof(shm_stream_mod_socket_t)); arg->client_socket = client_socket; pthread_create(&tid, NULL, run_server_recv_client_msg , (void *)arg); } return NULL; } -int mod_listen(void * _socket) { - mod_socket_t * socket = (mod_socket_t *) _socket; +int shm_stream_mod_socket_listen(void * _socket) { + shm_stream_mod_socket_t * socket = (shm_stream_mod_socket_t *) _socket; pthread_t tid; socket->is_server = 1; int rv = shm_listen(socket->shm_socket); @@ -116,14 +116,14 @@ } -int mod_connect(void * _socket, int port) { - mod_socket_t * socket = (mod_socket_t *) _socket; +int shm_stream_mod_socket_connect(void * _socket, int port) { + shm_stream_mod_socket_t * socket = (shm_stream_mod_socket_t *) _socket; return shm_connect(socket->shm_socket, port); } -int mod_send(void * _socket, const void *buf, const int size) { - mod_socket_t * socket = (mod_socket_t *) _socket; +int shm_stream_mod_socket_send(void * _socket, const void *buf, const int size) { + shm_stream_mod_socket_t * socket = (shm_stream_mod_socket_t *) _socket; std::map<int, shm_socket_t* > *clientSocketMap = socket->shm_socket->clientSocketMap; std::map<int, shm_socket_t* >::iterator iter; int rv; @@ -154,8 +154,8 @@ } -int mod_recv(void * _socket, void **buf, int *size) { - mod_socket_t * socket = (mod_socket_t *) _socket; +int shm_stream_mod_socket_recv(void * _socket, void **buf, int *size) { + shm_stream_mod_socket_t * socket = (shm_stream_mod_socket_t *) _socket; mod_entry_t entry; if(socket->is_server ) { @@ -189,13 +189,13 @@ return -1; } -int mod_get_socket_port(void * _socket) { - mod_socket_t * socket = (mod_socket_t *) _socket; +int shm_stream_mod_socket_get_port(void * _socket) { + shm_stream_mod_socket_t * socket = (shm_stream_mod_socket_t *) _socket; return socket->shm_socket->port; } -void mod_free(void *buf) { +void shm_stream_mod_socket_free(void *buf) { free(buf); } diff --git a/src/socket/shm_stream_mod_socket.h b/src/socket/shm_stream_mod_socket.h new file mode 100644 index 0000000..7af8fbc --- /dev/null +++ b/src/socket/shm_stream_mod_socket.h @@ -0,0 +1,77 @@ +#ifndef __shm_stream_mod_socket_SOCKET_H__ +#define __shm_stream_mod_socket_SOCKET_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + +enum socket_mod_t +{ + PULL_PUSH = 1, + REQ_REP = 2, + PAIR = 3, + PUB_SUB = 4, + SURVEY = 5, + BUS = 6 + +}; + +/** + * 鍒涘缓socket + * @return socket鍦板潃 +*/ +void *shm_stream_mod_socket_open(int mod); + +/** + * 鍏抽棴socket + * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜 +*/ +int shm_stream_mod_socket_close(void * _socket); + +/** + * 缁戝畾绔彛鍒皊ocket, 濡傛灉涓嶇粦瀹氬垯绯荤粺鑷姩鍒嗛厤涓�涓� + * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜 +*/ +int shm_stream_mod_socket_bind(void * _socket, int port); + + +/** + * 鏈嶅姟绔紑鍚繛鎺ョ洃鍚� + * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜 + */ +int shm_stream_mod_socket_listen(void * _socket); + +/** + * 瀹㈡埛绔彂璧疯繛鎺ヨ姹� + */ +int shm_stream_mod_socket_connect(void * _socket, int port); + +/** + * 鍙戦�佷俊鎭� + * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜 + */ +int shm_stream_mod_socket_send(void * _socket, const void *buf, const int size); + +/** + * 鎺ユ敹淇℃伅 + * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜 +*/ +int shm_stream_mod_socket_recv(void * _socket, void **buf, int *size) ; + +/** + * 閲婃斁瀛樺偍鎺ユ敹淇℃伅鐨刡uf + */ +void shm_stream_mod_socket_free(void *buf); + + +/** + * 鑾峰彇soket绔彛鍙� + */ +int shm_stream_mod_socket_get_port(void * _socket); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file -- Gitblit v1.8.0