From 7fa99e0efe07a120af719da2cae5c1151f024403 Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期三, 03 四月 2024 10:17:25 +0800
Subject: [PATCH] remove some defer
---
src/net/net_mod_socket.cpp | 89 ++++++++++++++++++++++++++++++++------------
1 files changed, 64 insertions(+), 25 deletions(-)
diff --git a/src/net/net_mod_socket.cpp b/src/net/net_mod_socket.cpp
index 6a541d6..d10fbdc 100644
--- a/src/net/net_mod_socket.cpp
+++ b/src/net/net_mod_socket.cpp
@@ -22,7 +22,7 @@
NetModSocket::~NetModSocket() {
-
+
}
@@ -46,6 +46,27 @@
return shmModSocket.force_bind(key);
}
+int NetModSocket::reg(void *pData, int len, void **buf, int *size, const int timeout_ms, int flag) {
+
+ return shmModSocket.reg(pData, len, buf, size, timeout_ms, flag);
+}
+
+void NetModSocket::int_set(int data) {
+ int_val = data;
+}
+
+void NetModSocket::svr_set(int data) {
+ svr_val = data;
+}
+
+int NetModSocket::int_get(void) {
+ return int_val;
+}
+
+int NetModSocket::svr_get(void) {
+ return svr_val;
+}
+
// int NetModSocket::sendandrecv(net_node_t *node_arr, int arrlen, void *send_buf, int send_size,
// net_mod_recv_msg_t ** recv_arr, int *recv_arr_size) {
// return _sendandrecv_(node_arr, arrlen, send_buf,send_size, recv_arr, recv_arr_size, -1);
@@ -67,7 +88,7 @@
NetConnPool *mpool = (NetConnPool *)_pool;
delete mpool;
- logger->debug("destory connPool");
+
}
/* One-time key creation function */
@@ -100,7 +121,6 @@
if (mpool == NULL)
{
/* If first call from this thread, allocate buffer for thread, and save its location */
- logger->debug("Create connPool");
mpool = new NetConnPool();
if (mpool == NULL) {
LoggerFactory::getLogger()->error(errno, "NetModSocket::_sendandrecv_ malloc");
@@ -320,6 +340,29 @@
}
+void NetModSocket::buf_data_set(std::string str, int val) {
+ recvbuf.insert({str, val});
+}
+
+int NetModSocket::buf_data_get(std::string str) {
+
+ int i;
+ int val = 0;
+ std::map<std::string, int>::iterator recvIter;
+
+ recvIter = recvbuf.find(str);
+ if(recvIter != recvbuf.end()) {
+
+ val = recvIter->second;
+
+ }
+
+ return val;
+}
+
+void NetModSocket::buf_data_del(std::string str) {
+ recvbuf.erase(str);
+}
void NetModSocket::free_recv_msg_arr(net_mod_recv_msg_t * arr, size_t size) {
@@ -343,9 +386,6 @@
return _pub_(node_arr, arrlen, topic, topic_size, content, content_size, msec);
}
-
-// int pub(char *topic, int topic_size, void *content, int content_size, int port);
-
int NetModSocket::_pub_(net_node_t *node_arr, int arrlen, const char *topic, int topic_size, const void *content,
int content_size, int msec) {
int i, connfd;
@@ -363,7 +403,7 @@
net_mod_err_t err_msg;
// 鏈湴鍙戦��
- if(node_arr == NULL || arrlen == 0) {
+ if ((node_arr == NULL) || (arrlen == 0)) {
if(msec == 0) {
ret = shmModSocket.pub(topic, topic_size, content, content_size, SHM_BUS_KEY, NULL, BUS_NOWAIT_FLAG);
} else if(msec > 0) {
@@ -487,20 +527,20 @@
* @key 鍙戦�佺粰璋�
* @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜
*/
-int NetModSocket::sendto(const void *buf, const int size, const int key){
- return shmModSocket.sendto(buf, size, key);
+int NetModSocket::sendto(const void *buf, const int size, const int key, int reset, int data_set){
+ return shmModSocket.sendto(buf, size, key, 0, 0, reset, data_set);
}
// 鍙戦�佷俊鎭秴鏃惰繑鍥炪�� @sec 绉� 锛� @nsec 绾崇
-int NetModSocket::sendto_timeout(const void *buf, const int size, const int key, int sec, int nsec){
+int NetModSocket::sendto_timeout(const void *buf, const int size, const int key, int sec, int nsec, int reset, int data_set){
struct timespec timeout = {sec, nsec};
- return shmModSocket.sendto(buf, size, key, &timeout, BUS_TIMEOUT_FLAG);
+ return shmModSocket.sendto(buf, size, key, &timeout, BUS_TIMEOUT_FLAG, reset, data_set);
}
// 鍙戦�佷俊鎭珛鍒昏繑鍥炪��
-int NetModSocket::sendto_nowait(const void *buf, const int size, const int key){
- return shmModSocket.sendto(buf, size, key, NULL, BUS_NOWAIT_FLAG);
+int NetModSocket::sendto_nowait(const void *buf, const int size, const int key, int reset, int data_set){
+ return shmModSocket.sendto(buf, size, key, NULL, BUS_NOWAIT_FLAG, reset, data_set);
}
@@ -509,23 +549,22 @@
* @key 浠庤皝鍝噷鏀跺埌鐨勪俊鎭�
* @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜
*/
-int NetModSocket::recvfrom(void **buf, int *size, int *key) {
+int NetModSocket::recvfrom(void **buf, int *size, int *key, int reset, int data_set) {
- return shmModSocket.recvfrom(buf, size, key);
+ return shmModSocket.recvfrom(buf, size, key, 0, 0, reset, data_set);
}
// 鎺ュ彈淇℃伅瓒呮椂杩斿洖銆� @sec 绉� 锛� @nsec 绾崇
-int NetModSocket::recvfrom_timeout(void **buf, int *size, int *key, int sec, int nsec){
+int NetModSocket::recvfrom_timeout(void **buf, int *size, int *key, int sec, int nsec, int reset, int data_set){
struct timespec timeout = {sec, nsec};
- return shmModSocket.recvfrom(buf, size, key, &timeout, BUS_TIMEOUT_FLAG);
+ return shmModSocket.recvfrom(buf, size, key, &timeout, BUS_TIMEOUT_FLAG, reset, data_set);
}
-int NetModSocket::recvfrom_nowait(void **buf, int *size, int *key){
- return shmModSocket.recvfrom(buf, size, key, NULL, BUS_NOWAIT_FLAG);
+int NetModSocket::recvfrom_nowait(void **buf, int *size, int *key, int reset, int data_set){
+ return shmModSocket.recvfrom(buf, size, key, NULL, BUS_NOWAIT_FLAG, reset, data_set);
}
-
int NetModSocket::recvandsend(recvandsend_callback_fn callback,
const struct timespec *timeout , int flag, void * user_data ) {
@@ -764,23 +803,23 @@
head.mod = ntohl(GET(tmp_ptr));
- tmp_ptr += 4;
+ tmp_ptr += sizeof(uint32_t);
memcpy(head.host, tmp_ptr, sizeof(head.host));
tmp_ptr += sizeof(head.host);
head.port = ntohl(GET(tmp_ptr));
- tmp_ptr += 4;
+ tmp_ptr += sizeof(uint32_t);
head.key = ntohl(GET(tmp_ptr));
- tmp_ptr += 4;
+ tmp_ptr += sizeof(uint32_t);
head.content_length = ntohl(GET(tmp_ptr));
- tmp_ptr += 4;
+ tmp_ptr += sizeof(uint32_t);
head.topic_length = ntohl(GET(tmp_ptr));
- tmp_ptr += 4;
+ tmp_ptr += sizeof(uint32_t);
head.timeout = ntohl(GET_INT32(tmp_ptr));
return head;
--
Gitblit v1.8.0