服务端支持多个连接

multi_conns
BlueMatthew 2 years ago
parent 7b6b1baf1b
commit bd214bc82d

@ -118,6 +118,7 @@ typedef struct {
typedef struct typedef struct
{ {
int sockid;
int iLength ; // 接收长度 int iLength ; // 接收长度
unsigned short usISUType; // 0,2=I ; 1=S ; 3=U unsigned short usISUType; // 0,2=I ; 1=S ; 3=U
unsigned short usSendNo; // 发送序号 unsigned short usSendNo; // 发送序号

@ -41,7 +41,7 @@
#include <vector> #include <vector>
#include <iostream> #include <iostream>
#define _HT_OPENCV_APP // 图片分析处理程序 // #define _HT_OPENCV_APP // 图片分析处理程序
#define _HT_IEC104_APP // IEC104通讯程序 #define _HT_IEC104_APP // IEC104通讯程序
#define _DEF_HMF_VOLTAGE // 黑麋峰高压侧电流计算 #define _DEF_HMF_VOLTAGE // 黑麋峰高压侧电流计算
#define _DEF_DB_CHANGERATE // 启用偏差率入库功能,否则以设定的间隔时间入库 #define _DEF_DB_CHANGERATE // 启用偏差率入库功能,否则以设定的间隔时间入库
@ -56,6 +56,8 @@ extern TConfig g_TConfig;
extern TTcpSocket g_Tcp; extern TTcpSocket g_Tcp;
extern ST_IEC104_CTRL g_IecCtrl; // socket linker info and status extern ST_IEC104_CTRL g_IecCtrl; // socket linker info and status
extern int g_MaxScokId; // socket linker info and status
extern std::map<int, ST_IEC104_CTRL> g_IecCtrls;
extern mutex g_IecCtrl_mutex; // socket linker on mutex extern mutex g_IecCtrl_mutex; // socket linker on mutex
extern map<string, ST_BYQWORK_STATUS> g_map_work; // 主变工作状态缓存 extern map<string, ST_BYQWORK_STATUS> g_map_work; // 主变工作状态缓存

@ -55,7 +55,6 @@ protected:
}; };
void IEC104EnvFree(); void IEC104EnvFree();
void IEC104EnvLoad(); void IEC104EnvLoad();
void UpdateLastTime();
void *thread_listen_proc(void *arg); void *thread_listen_proc(void *arg);
void *thread_client_proc(void *arg); void *thread_client_proc(void *arg);

@ -19,6 +19,8 @@ TTcpSocket g_Tcp;
int g_Running; int g_Running;
ST_IEC104_CTRL g_IecCtrl; // socket linker info and status ST_IEC104_CTRL g_IecCtrl; // socket linker info and status
std::map<int, ST_IEC104_CTRL> g_IecCtrls;
int g_MaxScokId; // socket linker info and status
mutex g_IecCtrl_mutex; // socket linker on mutex mutex g_IecCtrl_mutex; // socket linker on mutex
int g_seqno; // 与MEC之间交换的流水号 int g_seqno; // 与MEC之间交换的流水号

File diff suppressed because it is too large Load Diff

@ -337,12 +337,12 @@ int main(int argc, char* argv[])
ht_pthread_create_background(&thread_handle_linkmgr, thread_listen_proc, NULL); // 链路管理线程 ht_pthread_create_background(&thread_handle_linkmgr, thread_listen_proc, NULL); // 链路管理线程
ht_pthread_create_background(&thread_handle_recv, thread_recv_proc, NULL); // ht_pthread_create_background(&thread_handle_recv, thread_recv_proc, NULL);
// ht_pthread_create_background(&thread_handle_linkmgr, thread_client_proc, NULL); // 链路管理线程 // ht_pthread_create_background(&thread_handle_linkmgr, thread_client_proc, NULL); // 链路管理线程
ht_pthread_create_background(&thread_handle_parse, thread_parser_proc, NULL); // 104报文解析线程 ht_pthread_create_background(&thread_handle_parse, thread_parser_proc, NULL); // 104报文解析线程
ht_pthread_create_background(&thread_handle_timer, thread_Timer_proc, NULL); // 104链路超时管理线程 ht_pthread_create_background(&thread_handle_timer, thread_Timer_proc, NULL); // 104链路超时管理线程
ht_pthread_create_background(&thread_handle_active, thread_active_proc, NULL); // 104报文应答线程 // ht_pthread_create_background(&thread_handle_active, thread_active_proc, NULL); // 104报文应答线程
#endif #endif
#ifdef _HT_OPENCV_APP #ifdef _HT_OPENCV_APP
ht_pthread_create_background(&thread_handle_opecvimg, thread_opencv_proc, NULL); // 图片解析线程 ht_pthread_create_background(&thread_handle_opecvimg, thread_opencv_proc, NULL); // 图片解析线程

@ -61,9 +61,15 @@ int TTcpSocket::tcpCloseSocket(int sockfd)
//if(_close(sockfd) == -1) //if(_close(sockfd) == -1)
if (shutdown(sockfd, 2) == -1) if (shutdown(sockfd, 2) == -1)
#else #else
if(close(sockfd) == -1) if (shutdown(sockfd, SHUT_RDWR) == -1)
#endif #endif
vPrtLogMsg(LOG_WARNG, RET_FAIL, "_close sockid=%d return:%d:%s", sockfd, errno, strerror(errno)); vPrtLogMsg(LOG_WARNG, RET_FAIL, "_close sockid=%d return:%d:%s", sockfd, errno, strerror(errno));
else
#ifdef _WIN32
closesocket(sockfd);
#else
close(sockfd);
#endif
return 1; return 1;
} }
return 0 ; return 0 ;
@ -396,7 +402,8 @@ int TTcpSocket::tcpRecvBuffer(int sockid, char* pBuffer,int nMaxLength, int time
struct timeval st_TimeOut; struct timeval st_TimeOut;
int isel = 0; int isel = 0;
if( sockid <= 0 || pBuffer == NULL) return -1; // if( sockid <= 0 || pBuffer == NULL) return -1;
while(iTop != nMaxLength) while(iTop != nMaxLength)
{ {
st_TimeOut.tv_sec = timeout ; st_TimeOut.tv_sec = timeout ;

Loading…
Cancel
Save