Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
FreemudAPI
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
FreemudAPI
Commits
eb71674e
Commit
eb71674e
authored
Jan 10, 2020
by
刘帅
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
使用c++11的utf8字符串,要求使用支持c++11的编译器,另外使用静态链接
parent
0d9668ae
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
29 additions
and
18 deletions
+29
-18
FreemudAPI/FreemudAPI.cpp
+10
-10
FreemudAPI/FreemudAPI.vcxproj
+8
-1
FreemudAPI/fm_log.h
+1
-1
FreemudAPI/recv.h
+4
-4
FreemudAPI/send.h
+1
-1
test/test.vcxproj
+5
-1
No files found.
FreemudAPI/FreemudAPI.cpp
View file @
eb71674e
...
...
@@ -32,11 +32,11 @@ extern "C" __declspec(dllexport) int __stdcall FMGetResponse(const char* req, ch
//Log("Initialising Winsock...");
if
(
WSAStartup
(
MAKEWORD
(
2
,
2
),
&
wsa
)
!=
0
)
{
MakeError
(
"Error. Startup error: %d. Server: %s, Port: %d"
,
WSAGetLastError
(),
setting
.
ip
.
c_str
(),
setting
.
port
)
MakeError
(
u8
"Error. Startup error: %d. Server: %s, Port: %d"
,
WSAGetLastError
(),
setting
.
ip
.
c_str
(),
setting
.
port
)
}
if
(
isOk
&&
(
_socket
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
))
==
INVALID_SOCKET
)
{
MakeError
(
"Could not create socket: %d. Server: %s, Port: %d"
,
WSAGetLastError
(),
setting
.
ip
.
c_str
(),
setting
.
port
)
MakeError
(
u8
"Could not create socket: %d. Server: %s, Port: %d"
,
WSAGetLastError
(),
setting
.
ip
.
c_str
(),
setting
.
port
)
}
_server
.
sin_addr
.
S_un
.
S_addr
=
(
ULONG
)
inet_addr
(
setting
.
ip
.
c_str
());
...
...
@@ -48,16 +48,16 @@ extern "C" __declspec(dllexport) int __stdcall FMGetResponse(const char* req, ch
if
(
isOk
&&
connect
(
_socket
,
(
struct
sockaddr
*
)
&
_server
,
sizeof
(
_server
))
<
0
)
{
MakeError
(
"Error. connect error: %d. Server: %s, Port: %d"
,
WSAGetLastError
(),
setting
.
ip
.
c_str
(),
setting
.
port
)
MakeError
(
u8
"Error. connect error: %d. Server: %s, Port: %d"
,
WSAGetLastError
(),
setting
.
ip
.
c_str
(),
setting
.
port
)
}
//if (isOk && send(_socket, req, strlen(req), 0) < 0)
if
(
isOk
&&
Send
(
_socket
,
req
)
<
0
)
{
MakeError
(
"Error. Send error: %d. Server: %s, Port: %d"
,
WSAGetLastError
(),
setting
.
ip
.
c_str
(),
setting
.
port
)
MakeError
(
u8
"Error. Send error: %d. Server: %s, Port: %d"
,
WSAGetLastError
(),
setting
.
ip
.
c_str
(),
setting
.
port
)
}
if
(
isOk
)
{
LOG
()
<<
"Send data: "
<<
req
;
LOG
()
<<
u8
"Send data: "
<<
req
;
}
int
recv_size
=
SOCKET_ERROR
;
...
...
@@ -66,19 +66,19 @@ extern "C" __declspec(dllexport) int __stdcall FMGetResponse(const char* req, ch
memset
(
rsp
,
0
,
byteSize
);
if
(
isOk
&&
(
recv_size
=
Recv
(
_socket
,
rsp
,
byteSize
-
1
))
==
SOCKET_ERROR
)
{
MakeError
(
"Error. Recv error: %d. Server: %s, Port: %d"
,
WSAGetLastError
(),
setting
.
ip
.
c_str
(),
setting
.
port
)
MakeError
(
u8
"Error. Recv error: %d. Server: %s, Port: %d"
,
WSAGetLastError
(),
setting
.
ip
.
c_str
(),
setting
.
port
)
}
else
if
(
recv_size
==
FMError_ConnectClosed
.
Code
())
{
MakeError
(
"Error. %s(%d). Server: %s, Port: %d"
,
FMError_ConnectClosed
.
MsgCStr
(),
WSAGetLastError
(),
setting
.
ip
.
c_str
(),
setting
.
port
)
MakeError
(
u8
"Error. %s(%d). Server: %s, Port: %d"
,
FMError_ConnectClosed
.
MsgCStr
(),
WSAGetLastError
(),
setting
.
ip
.
c_str
(),
setting
.
port
)
}
else
if
(
recv_size
==
FMError_IncorrectHeader
.
Code
())
{
MakeError
(
"Error. %s. Server: %s, Port: %d"
,
FMError_IncorrectHeader
.
MsgCStr
(),
setting
.
ip
.
c_str
(),
setting
.
port
)
MakeError
(
u8
"Error. %s. Server: %s, Port: %d"
,
FMError_IncorrectHeader
.
MsgCStr
(),
setting
.
ip
.
c_str
(),
setting
.
port
)
}
else
if
(
recv_size
==
FMError_BufferOverflow
.
Code
())
{
MakeError
(
"Error. %s. Server: %s, Port: %d"
,
FMError_BufferOverflow
.
MsgCStr
(),
setting
.
ip
.
c_str
(),
setting
.
port
)
MakeError
(
u8
"Error. %s. Server: %s, Port: %d"
,
FMError_BufferOverflow
.
MsgCStr
(),
setting
.
ip
.
c_str
(),
setting
.
port
)
}
if
(
isOk
)
{
LOG
()
<<
"Recv size: "
<<
recv_size
<<
" Recv data: "
<<
rsp
;
}
else
if
(
_error
.
Code
()
==
FM_ERROR_CODE_SOCKET
)
{
sprintf
(
ErrorMsg
,
"{
\"
statusCode
\"
: 104,
\"
msg
\"
:
\"
本地Socket通讯错误(%s).
\"
}"
,
_error
.
Msg
().
c_str
());
sprintf
(
ErrorMsg
,
u8
"{
\"
statusCode
\"
: 104,
\"
msg
\"
:
\"
本地Socket通讯错误(%s).
\"
}"
,
_error
.
Msg
().
c_str
());
strcpy
(
rsp
,
ErrorMsg
);
}
...
...
FreemudAPI/FreemudAPI.vcxproj
View file @
eb71674e
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="
1
4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
...
...
@@ -22,29 +22,36 @@
<ProjectGuid>{18C1BF83-598C-42F3-B8AD-B770B3F405C0}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>FreemudAPI</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
<UseOfMfc>Static</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<UseOfMfc>Static</UseOfMfc>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
...
...
FreemudAPI/fm_log.h
View file @
eb71674e
...
...
@@ -59,7 +59,7 @@ public :
std
::
stringstream
sstr
;
sstr
<<
"FreemudAPI"
<<
t
->
tm_year
+
1900
<<
t
->
tm_mon
+
1
<<
t
->
tm_mday
;
sstr
<<
u8"FreemudAPI"
<<
t
->
tm_year
+
1900
<<
t
->
tm_mon
+
1
<<
t
->
tm_mday
;
std
::
string
filename
=
std
::
string
(
sstr
.
str
().
c_str
());
...
...
FreemudAPI/recv.h
View file @
eb71674e
...
...
@@ -13,13 +13,13 @@ int _Recv(SOCKET socket, char *ptr, int length)
LOG
()
<<
"Error: EINTR."
;
continue
;
}
LOG
()
<<
"Error: other recv error."
;
LOG
()
<<
u8
"Error: other recv error."
;
return
totalLen
;
}
else
if
(
totalLen
==
0
)
{
LOG
()
<<
"Error: connect closed."
;
LOG
()
<<
u8
"Error: connect closed."
;
return
0
;
}
LOG
()
<<
"Total: Size: "
<<
totalLen
<<
" Data: "
<<
ptr
;
LOG
()
<<
u8"Total: Size: "
<<
totalLen
<<
u8
" Data: "
<<
ptr
;
}
while
(
0
);
return
totalLen
;
...
...
@@ -68,7 +68,7 @@ int Recv(SOCKET socket, char *ptr, unsigned int byteSize)
}
if
(
byteSize
<
dataLen
)
{
// 判断接收Buffer长度是否足够
LOG
()
<<
"Error. Buffer overflow, Except size: "
<<
byteSize
<<
" Actual size: "
<<
dataLen
;
LOG
()
<<
u8"Error. Buffer overflow, Except size: "
<<
byteSize
<<
u8
" Actual size: "
<<
dataLen
;
delete
[]
recvBuf
;
delete
[]
tempBuf
;
return
FMError_BufferOverflow
.
Code
();
...
...
FreemudAPI/send.h
View file @
eb71674e
...
...
@@ -20,7 +20,7 @@ int Send(SOCKET socket, const char *ptr)
int
tempLen
=
-
1
;
if
(
(
tempLen
=
send
(
socket
,
sendData
,
sendLength
,
0
))
<
0
)
{
LOG
()
<<
"Error: other error."
;
LOG
()
<<
u8
"Error: other error."
;
}
if
(
setting
.
needSocketHeaderSend
)
{
...
...
test/test.vcxproj
View file @
eb71674e
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="
1
4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
...
...
@@ -28,23 +28,27 @@
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
...
...
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