Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
FMVip_LXJ
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhenfei.zhang
FMVip_LXJ
Commits
4da0b670
Commit
4da0b670
authored
Jul 20, 2017
by
NitefullWind
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1. 更新DLL,Socket在返回数据一定时间后再断开。
parent
ebd75d4b
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
8 deletions
+50
-8
FMVipDC/FMVipDC.pro
+1
-1
FMVipDC/fmsockserver.cpp
+38
-5
FMVipDC/fmsockserver.h
+11
-2
No files found.
FMVipDC/FMVipDC.pro
View file @
4da0b670
...
@@ -2,7 +2,7 @@ QT -= core
...
@@ -2,7 +2,7 @@ QT -= core
TEMPLATE
=
lib
TEMPLATE
=
lib
CONFIG
+=
dll
CONFIG
+=
dll
c
++
11
DEFINES
+=
FMSOCK_BUILD
_UNICODE
DEFINES
+=
FMSOCK_BUILD
_UNICODE
...
...
FMVipDC/fmsockserver.cpp
View file @
4da0b670
#include "fmsockserver.h"
#include "fmsockserver.h"
#include <fmutils/fmutils.hpp>
#include <fmutils/fmutils.hpp>
// 定时关闭Socket连接
void
CloseSocket
()
{
while
(
!
SocketStop
)
{
for
(
std
::
list
<
ENDSOCKET
>::
iterator
it
=
EndSocketList
.
begin
();
it
!=
EndSocketList
.
end
();
it
++
)
{
if
(
it
->
times
==
120
)
{
closesocket
(
it
->
socket
);
}
it
->
times
+=
1
;
}
if
(
!
EndSocketList
.
empty
()
&&
EndSocketList
.
begin
()
->
times
>
120
)
{
EndSocketList
.
pop_front
();
}
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
1
*
1000
));
}
for
(
std
::
list
<
ENDSOCKET
>::
iterator
it
=
EndSocketList
.
begin
();
it
!=
EndSocketList
.
end
();
it
++
)
{
closesocket
(
it
->
socket
);
}
EndSocketList
.
clear
();
}
FMSockServer
::
FMSockServer
(
FMApiRelay
*
relay
)
:
FMSockServer
::
FMSockServer
(
FMApiRelay
*
relay
)
:
_worker
(
0
),
_worker
(
0
),
_worker_tid
(
0
),
_worker_tid
(
0
),
...
@@ -28,6 +49,8 @@ FMSockServer::FMSockServer(FMApiRelay *relay) :
...
@@ -28,6 +49,8 @@ FMSockServer::FMSockServer(FMApiRelay *relay) :
_addr_in
.
sin_family
=
AF_INET
;
_addr_in
.
sin_family
=
AF_INET
;
_addr_in
.
sin_addr
.
S_un
.
S_addr
=
htonl
(
INADDR_ANY
);
_addr_in
.
sin_addr
.
S_un
.
S_addr
=
htonl
(
INADDR_ANY
);
_closeSocketThread
=
std
::
thread
(
CloseSocket
);
}
}
...
@@ -39,6 +62,9 @@ FMSockServer::~FMSockServer()
...
@@ -39,6 +62,9 @@ FMSockServer::~FMSockServer()
WSACleanup
();
WSACleanup
();
DeleteCriticalSection
(
&
_cs
);
DeleteCriticalSection
(
&
_cs
);
SocketStop
=
true
;
_closeSocketThread
.
join
();
}
}
...
@@ -211,23 +237,30 @@ void FMSockServer::RecvRoutine(DWORD err, DWORD bytes, LPWSAOVERLAPPED overlappe
...
@@ -211,23 +237,30 @@ void FMSockServer::RecvRoutine(DWORD err, DWORD bytes, LPWSAOVERLAPPED overlappe
if
(
io_data
->
relay
)
{
if
(
io_data
->
relay
)
{
io_data
->
relay
->
Transfer
(
io_data
->
msg
,
response
,
len
);
io_data
->
relay
->
Transfer
(
io_data
->
msg
,
response
,
len
);
}
}
// unsigned long mode = 0;
// int res = ioctlsocket(io_data->socket, FIONBIO, &mode);
if
(
response
)
{
if
(
response
)
{
// HANDLE writeEvent = WSACreateEvent();
// WSAEventSelect(io_data->socket, writeEvent, FD_WRITE);
// WaitForSingleObject(writeEvent, 5000);
send
(
io_data
->
socket
,
response
,
len
,
0
);
send
(
io_data
->
socket
,
response
,
len
,
0
);
FMLOG
(
"Transfered %s"
,
response
);
FMLOG
(
"Transfered %s"
,
response
);
}
}
else
{
else
{
FMLOG
(
_T
(
"Failed to determine response data."
));
FMLOG
(
_T
(
"Failed to determine response data."
));
}
}
HANDLE
closeEvent
=
WSACreateEvent
();
//
HANDLE closeEvent = WSACreateEvent();
WSAEventSelect
(
io_data
->
socket
,
closeEvent
,
FD_CLOSE
);
//
WSAEventSelect(io_data->socket, closeEvent, FD_CLOSE);
DWORD
dwRet
=
WaitForSingleObject
(
closeEvent
,
5000
);
//
DWORD dwRet = WaitForSingleObject(closeEvent, 5000);
// if(dwRet == WSA_WAIT_EVENT_0) {
// if(dwRet == WSA_WAIT_EVENT_0) {
closesocket
(
io_data
->
socket
);
//
closesocket(io_data->socket);
// }
// }
WSACloseEvent
(
closeEvent
);
// WSACloseEvent(closeEvent);
EndSocketList
.
push_back
({
io_data
->
socket
,
0
});
//! Free all buffer
//! Free all buffer
HeapFree
(
GetProcessHeap
(),
0
,
io_data
);
HeapFree
(
GetProcessHeap
(),
0
,
io_data
);
...
...
FMVipDC/fmsockserver.h
View file @
4da0b670
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
#include <Windows.h>
#include <Windows.h>
#include <winsock2.h>
#include <winsock2.h>
#include <list>
#include <list>
#include <thread>
#define BACKLOG 5
#define BACKLOG 5
...
@@ -42,6 +43,15 @@ typedef struct
...
@@ -42,6 +43,15 @@ typedef struct
}
FMSOCKDATA
,
*
LPFMSOCKDATA
;
}
FMSOCKDATA
,
*
LPFMSOCKDATA
;
//!
typedef
struct
{
SOCKET
socket
;
int
times
;
}
ENDSOCKET
;
static
std
::
list
<
ENDSOCKET
>
EndSocketList
;
static
bool
SocketStop
=
false
;
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//! Class FMSocketServer
//! Class FMSocketServer
...
@@ -60,7 +70,6 @@ public:
...
@@ -60,7 +70,6 @@ public:
VOID
SetRelay
(
FMApiRelay
*
relay
);
VOID
SetRelay
(
FMApiRelay
*
relay
);
protected
:
protected
:
BOOL
_Listen
();
BOOL
_Listen
();
...
@@ -76,7 +85,7 @@ private:
...
@@ -76,7 +85,7 @@ private:
FMApiRelay
*
_relay
;
FMApiRelay
*
_relay
;
CRITICAL_SECTION
_cs
;
CRITICAL_SECTION
_cs
;
std
::
thread
_closeSocketThread
;
};
};
//#ifdef __cplusplus
//#ifdef __cplusplus
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment