Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
fc4f125f
Commit
fc4f125f
authored
Aug 23, 2016
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Переход на libPoco]: (UNetUDP): добился прохождения теста
parent
c127f9e5
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
47 additions
and
39 deletions
+47
-39
UNetReceiver.cc
extensions/UNetUDP/UNetReceiver.cc
+13
-1
UNetReceiver.h
extensions/UNetUDP/UNetReceiver.h
+1
-0
UNetSender.cc
extensions/UNetUDP/UNetSender.cc
+14
-4
UNetSender.h
extensions/UNetUDP/UNetSender.h
+1
-0
test_unetudp.cc
extensions/UNetUDP/tests/test_unetudp.cc
+5
-4
urecv_perf_test.cc
extensions/UNetUDP/tests/urecv_perf_test.cc
+1
-1
unet-udp-tester.cc
extensions/UNetUDP/unet-udp-tester.cc
+2
-2
UDPCore.h
include/UDPCore.h
+9
-26
test_tcpcheck.cc
tests/test_tcpcheck.cc
+1
-1
No files found.
extensions/UNetUDP/UNetReceiver.cc
View file @
fc4f125f
...
...
@@ -16,6 +16,7 @@
// -------------------------------------------------------------------------
#include <sstream>
#include <iomanip>
#include <Poco/Net/NetException.h>
#include "Exceptions.h"
#include "Extensions.h"
#include "UNetReceiver.h"
...
...
@@ -43,6 +44,7 @@ UNetReceiver::UNetReceiver(const std::string& s_host, int _port, const std::shar
recvpause
(
10
),
updatepause
(
100
),
port
(
_port
),
saddr
(
s_host
,
_port
),
recvTimeout
(
5000
),
prepareTime
(
2000
),
lostTimeout
(
200
),
/* 2*updatepause */
...
...
@@ -170,7 +172,8 @@ bool UNetReceiver::createConnection( bool throwEx )
try
{
udp
=
make_shared
<
UDPReceiveU
>
(
addr
,
port
);
udp
->
setCompletion
(
false
);
// делаем неблокирующее чтение (нужно для libev)
//udp = make_shared<UDPReceiveU>();
udp
->
setBlocking
(
false
);
// делаем неблокирующее чтение (нужно для libev)
evReceive
.
set
<
UNetReceiver
,
&
UNetReceiver
::
callback
>
(
this
);
if
(
evCheckConnection
.
is_active
()
)
...
...
@@ -624,7 +627,10 @@ void UNetReceiver::stop()
// -----------------------------------------------------------------------------
bool
UNetReceiver
::
receive
()
{
try
{
ssize_t
ret
=
udp
->
receiveBytes
(
r_buf
.
data
,
sizeof
(
r_buf
.
data
));
//ssize_t ret = udp->receiveFrom(r_buf.data, sizeof(r_buf.data),saddr);
if
(
ret
<
0
)
{
...
...
@@ -645,6 +651,12 @@ bool UNetReceiver::receive()
unetcrit
<<
myname
<<
"(receive): FAILED RECEIVE DATA ret="
<<
ret
<<
endl
;
return
false
;
}
}
catch
(
Poco
::
Net
::
NetException
&
ex
)
{
unetcrit
<<
myname
<<
"(receive): recv err: "
<<
ex
.
displayText
()
<<
endl
;
return
false
;
}
if
(
pack
.
magic
!=
UniSetUDP
::
UNETUDP_MAGICNUM
)
{
...
...
extensions/UNetUDP/UNetReceiver.h
View file @
fc4f125f
...
...
@@ -208,6 +208,7 @@ class UNetReceiver:
std
::
shared_ptr
<
UDPReceiveU
>
udp
;
std
::
string
addr
;
int
port
=
{
0
};
Poco
::
Net
::
SocketAddress
saddr
;
std
::
string
myname
;
ev
::
io
evReceive
;
ev
::
periodic
evCheckConnection
;
...
...
extensions/UNetUDP/UNetSender.cc
View file @
fc4f125f
...
...
@@ -35,6 +35,7 @@ UNetSender::UNetSender(const std::string& _host, const int _port, const std::sha
shm
(
smi
),
port
(
_port
),
s_host
(
_host
),
saddr
(
_host
,
_port
),
sendpause
(
150
),
packsendpause
(
5
),
activated
(
false
),
...
...
@@ -111,8 +112,11 @@ bool UNetSender::createConnection( bool throwEx )
try
{
udp
=
make_shared
<
UDPSocketU
>
(
addr
,
port
);
//udp = make_shared<UDPSocketU>(addr, port);
udp
=
make_shared
<
UDPSocketU
>
();
udp
->
setBroadcast
(
true
);
udp
->
setSendTimeout
(
writeTimeout
*
1000
);
// udp->setNoDelay(true);
}
catch
(
const
std
::
exception
&
e
)
{
...
...
@@ -301,14 +305,20 @@ void UNetSender::real_send( UniSetUDP::UDPMessage& mypack )
if
(
packetnum
==
0
)
packetnum
=
1
;
if
(
!
udp
||
!
udp
->
poll
(
writeTimeout
,
Poco
::
Net
::
Socket
::
SELECT_WRITE
)
)
if
(
!
udp
||
!
udp
->
poll
(
writeTimeout
*
1000
,
Poco
::
Net
::
Socket
::
SELECT_WRITE
)
)
return
;
mypack
.
transport_msg
(
s_msg
);
size_t
ret
=
udp
->
sendBytes
(
(
char
*
)
s_msg
.
data
,
s_msg
.
len
);
try
{
size_t
ret
=
udp
->
sendTo
((
char
*
)
s_msg
.
data
,
s_msg
.
len
,
saddr
);
if
(
ret
<
s_msg
.
len
)
unetcrit
<<
myname
<<
"(real_send): FAILED ret="
<<
ret
<<
" < sizeof="
<<
s_msg
.
len
<<
endl
;
}
catch
(
Poco
::
Net
::
NetException
&
ex
)
{
unetcrit
<<
myname
<<
"(real_send): error: "
<<
ex
.
displayText
()
<<
endl
;
}
}
// -----------------------------------------------------------------------------
void
UNetSender
::
stop
()
...
...
extensions/UNetUDP/UNetSender.h
View file @
fc4f125f
...
...
@@ -175,6 +175,7 @@ class UNetSender
std
::
string
addr
;
int
port
=
{
0
};
std
::
string
s_host
=
{
""
};
Poco
::
Net
::
SocketAddress
saddr
;
std
::
string
myname
=
{
""
};
timeout_t
sendpause
=
{
150
};
...
...
extensions/UNetUDP/tests/test_unetudp.cc
View file @
fc4f125f
...
...
@@ -23,6 +23,7 @@ static int s_port = 3003; // Node2
static
int
s_nodeID
=
3003
;
static
int
s_procID
=
123
;
static
int
s_numpack
=
1
;
static
Poco
::
Net
::
SocketAddress
s_addr
(
host
,
s_port
);
static
ObjectId
node2_respond_s
=
12
;
static
ObjectId
node2_lostpackets_as
=
13
;
static
int
maxDifferense
=
5
;
// см. unetudp-test-configure.xml --unet-maxdifferense
...
...
@@ -48,7 +49,7 @@ void InitTest()
if
(
udp_s
==
nullptr
)
{
udp_s
=
make_shared
<
UDPSocketU
>
(
host
,
s_port
);
udp_s
=
make_shared
<
UDPSocketU
>
(
);
//(
host, s_port);
udp_s
->
setBroadcast
(
true
);
}
}
...
...
@@ -62,7 +63,7 @@ static UniSetUDP::UDPMessage receive( unsigned int pnum = 0, timeout_t tout = 20
while
(
ncycle
>
0
)
{
if
(
!
udp_r
->
poll
(
tout
,
Poco
::
Net
::
Socket
::
SELECT_READ
)
)
if
(
!
udp_r
->
poll
(
tout
*
1000
,
Poco
::
Net
::
Socket
::
SELECT_READ
)
)
break
;
size_t
ret
=
udp_r
->
receiveBytes
(
&
(
buf
.
data
),
sizeof
(
buf
.
data
)
);
...
...
@@ -80,7 +81,7 @@ static UniSetUDP::UDPMessage receive( unsigned int pnum = 0, timeout_t tout = 20
// -----------------------------------------------------------------------------
void
send
(
UniSetUDP
::
UDPMessage
&
pack
,
int
tout
=
2000
)
{
CHECK
(
udp_s
->
poll
(
tout
,
Poco
::
Net
::
Socket
::
SELECT_WRITE
)
);
CHECK
(
udp_s
->
poll
(
tout
*
1000
,
Poco
::
Net
::
Socket
::
SELECT_WRITE
)
);
pack
.
nodeID
=
s_nodeID
;
pack
.
procID
=
s_procID
;
...
...
@@ -88,7 +89,7 @@ void send( UniSetUDP::UDPMessage& pack, int tout = 2000 )
UniSetUDP
::
UDPPacket
s_buf
;
pack
.
transport_msg
(
s_buf
);
size_t
ret
=
udp_s
->
send
Bytes
((
char
*
)
&
s_buf
.
data
,
s_buf
.
len
);
size_t
ret
=
udp_s
->
send
To
((
char
*
)
&
s_buf
.
data
,
s_buf
.
len
,
s_addr
);
REQUIRE
(
ret
==
s_buf
.
len
);
}
// -----------------------------------------------------------------------------
...
...
extensions/UNetUDP/tests/urecv_perf_test.cc
View file @
fc4f125f
...
...
@@ -107,7 +107,7 @@ static void run_senders( size_t max, const std::string& s_host, size_t count = 5
{
try
{
if
(
udp
->
poll
(
100
,
Poco
::
Net
::
Socket
::
SELECT_WRITE
)
)
if
(
udp
->
poll
(
100
000
,
Poco
::
Net
::
Socket
::
SELECT_WRITE
)
)
{
mypack
.
transport_msg
(
s_buf
);
size_t
ret
=
udp
->
sendBytes
((
char
*
)
&
s_buf
.
data
,
s_buf
.
len
);
...
...
extensions/UNetUDP/unet-udp-tester.cc
View file @
fc4f125f
...
...
@@ -228,7 +228,7 @@ int main(int argc, char* argv[])
npack
=
0
;
}
if
(
!
udp
.
poll
(
tout
,
Poco
::
Net
::
Socket
::
SELECT_READ
)
)
if
(
!
udp
.
poll
(
tout
*
1000
,
Poco
::
Net
::
Socket
::
SELECT_READ
)
)
{
cout
<<
"(recv): Timeout.."
<<
endl
;
continue
;
...
...
@@ -326,7 +326,7 @@ int main(int argc, char* argv[])
try
{
if
(
udp
->
poll
(
tout
,
Poco
::
Net
::
Socket
::
SELECT_WRITE
)
)
if
(
udp
->
poll
(
tout
*
1000
,
Poco
::
Net
::
Socket
::
SELECT_WRITE
)
)
{
mypack
.
transport_msg
(
s_buf
);
...
...
include/UDPCore.h
View file @
fc4f125f
...
...
@@ -4,7 +4,7 @@
// -------------------------------------------------------------------------
#include <Poco/Net/DatagramSocket.h>
// -------------------------------------------------------------------------
//
различные к
лассы-обёртки, чтобы достучаться до "сырого сокета" и других функций
//
К
лассы-обёртки, чтобы достучаться до "сырого сокета" и других функций
// необходимых при использовании с libev..
// -------------------------------------------------------------------------
class
UDPSocketU
:
...
...
@@ -12,6 +12,10 @@ class UDPSocketU:
{
public
:
UDPSocketU
()
:
Poco
::
Net
::
DatagramSocket
(
Poco
::
Net
::
IPAddress
::
IPv4
)
{}
UDPSocketU
(
const
std
::
string
&
bind
,
int
port
)
:
Poco
::
Net
::
DatagramSocket
(
Poco
::
Net
::
SocketAddress
(
bind
,
port
),
true
)
{}
...
...
@@ -29,6 +33,10 @@ class UDPReceiveU:
{
public
:
UDPReceiveU
()
:
Poco
::
Net
::
DatagramSocket
(
Poco
::
Net
::
IPAddress
::
IPv4
)
{}
UDPReceiveU
(
const
std
::
string
&
bind
,
int
port
)
:
Poco
::
Net
::
DatagramSocket
(
Poco
::
Net
::
SocketAddress
(
bind
,
port
),
true
)
{}
...
...
@@ -39,31 +47,6 @@ class UDPReceiveU:
{
return
Poco
::
Net
::
DatagramSocket
::
sockfd
();
}
inline
void
setCompletion
(
bool
set
)
{
Poco
::
Net
::
DatagramSocket
::
setBlocking
(
set
);
}
};
// -------------------------------------------------------------------------
class
UDPDuplexU
:
public
Poco
::
Net
::
DatagramSocket
{
public
:
UDPDuplexU
(
const
std
::
string
&
bind
,
int
port
)
:
Poco
::
Net
::
DatagramSocket
(
Poco
::
Net
::
SocketAddress
(
bind
,
port
),
true
)
{}
virtual
~
UDPDuplexU
()
{}
int
getReceiveSocket
()
{
return
Poco
::
Net
::
DatagramSocket
::
sockfd
();;
}
void
setReceiveCompletion
(
bool
set
)
{
Poco
::
Net
::
DatagramSocket
::
setBlocking
(
set
);
}
};
// -------------------------------------------------------------------------
#endif // UDPReceiveU_H_
...
...
tests/test_tcpcheck.cc
View file @
fc4f125f
...
...
@@ -20,7 +20,7 @@ bool run_test_server()
while
(
!
cancel
)
{
if
(
sock
.
poll
(
500
,
Poco
::
Net
::
Socket
::
SELECT_READ
)
)
if
(
sock
.
poll
(
500
000
,
Poco
::
Net
::
Socket
::
SELECT_READ
)
)
{
}
...
...
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