Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
librf625
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
rf625
librf625
Commits
97cc2d49
Commit
97cc2d49
authored
7 years ago
by
pfilipch
Browse files
Options
Downloads
Patches
Plain Diff
add udp_send_datagram
parent
b9e2ae2b
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/sockfun.cpp
+19
-8
19 additions, 8 deletions
src/sockfun.cpp
with
19 additions
and
8 deletions
src/sockfun.cpp
+
19
−
8
View file @
97cc2d49
...
...
@@ -25,34 +25,45 @@ bool validate_host_address(uint32_t host_addr);
bool
recv_data
(
SOCKET
s
,
char
*
buf
,
size_t
nbytes
,
bool
accept_incomplete_packet
,
size_t
*
packet_size
)
{
ssize_t
nret
,
nrecv
=
0
;
ssize_t
nret
,
nrecv
=
0
;
if
(
!
buf
||
!
nbytes
)
{
return
false
;
}
do
{
nret
=
recv
(
s
,
&
buf
[
nrecv
],
ssize_t
(
nbytes
)
-
nrecv
,
0
);
nret
=
recv
(
s
,
&
buf
[
nrecv
],
ssize_t
(
nbytes
)
-
nrecv
,
0
);
if
(
nret
>
0
)
{
nrecv
+=
nret
;
}
}
while
(
nret
!=
SOCKET_ERROR
&&
!
accept_incomplete_packet
&&
(
nrecv
<
int
(
nbytes
)));
}
while
(
nret
!=
SOCKET_ERROR
&&
!
accept_incomplete_packet
&&
(
nrecv
<
int
(
nbytes
)));
if
(
accept_incomplete_packet
)
{
if
(
packet_size
)
*
packet_size
=
nrecv
;
return
(
nrecv
>
0
);
}
else
{
return
(
nrecv
==
int
(
nbytes
));
return
(
nrecv
==
int
(
nbytes
));
}
}
bool
send_data
(
SOCKET
s
,
const
char
*
buf
,
size_t
nbytes
)
{
ssize_t
nret
;
ssize_t
nret
;
if
(
!
buf
||
!
nbytes
)
{
return
false
;
}
nret
=
send
(
s
,
buf
,
ssize_t
(
nbytes
),
0
);
return
(
nret
==
ssize_t
(
nbytes
));
nret
=
send
(
s
,
buf
,
ssize_t
(
nbytes
),
0
);
return
(
nret
==
ssize_t
(
nbytes
));
}
bool
udp_send_datagram
(
SOCKET
s
,
char
*
buf
,
int
length
,
sockaddr_in
*
send_addr
)
{
int
nret
;
int
tolen
=
sizeof
(
sockaddr_in
);
if
(
!
buf
||
!
length
)
{
return
false
;
}
nret
=
sendto
(
s
,
buf
,
length
,
0
,
reinterpret_cast
<
struct
sockaddr
*>
(
send_addr
),
tolen
);
return
(
nret
==
length
);
}
bool
udp_recv_datagram
(
SOCKET
s
,
char
*
buf
,
size_t
max_length
,
size_t
*
datagram_size
,
sockaddr_in
*
from_addr
)
...
...
@@ -64,7 +75,7 @@ bool udp_recv_datagram(SOCKET s, char *buf, size_t max_length, size_t *datagram_
if
(
s
==
INVALID_SOCKET
)
{
return
false
;
}
nret
=
recvfrom
(
s
,
buf
,
ssize_t
(
max_length
),
0
,
reinterpret_cast
<
struct
sockaddr
*>
(
&
from_addr_l
),
&
from_size
);
nret
=
recvfrom
(
s
,
buf
,
ssize_t
(
max_length
),
0
,
reinterpret_cast
<
struct
sockaddr
*>
(
&
from_addr_l
),
&
from_size
);
if
(
nret
>
0
)
{
if
(
from_addr
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment