Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
DiSL
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
5
Issues
5
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DiSL
DiSL
Commits
a9f11b40
Commit
a9f11b40
authored
Apr 27, 2018
by
Lubomir Bulej
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add _full suffix to connection functions that expect to transfer data fully.
parent
4b2399d7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
20 deletions
+38
-20
src-disl-agent/connection.c
src-disl-agent/connection.c
+33
-16
src-disl-agent/connection.h
src-disl-agent/connection.h
+5
-4
No files found.
src-disl-agent/connection.c
View file @
a9f11b40
...
...
@@ -87,7 +87,7 @@ connection_close (struct connection * connection) {
typedef
ssize_t
(
*
xfer_fn
)
(
int
sockfd
,
void
*
buf
,
size_t
len
,
int
flags
);
static
inline
ssize_t
__socket_xfer
(
xfer_fn
xfer
,
const
int
sockfd
,
const
void
*
buf
,
const
s
size_t
len
)
{
__socket_xfer
_full
(
xfer_fn
xfer
,
const
int
sockfd
,
const
void
*
buf
,
const
size_t
len
)
{
unsigned
char
*
buf_tail
=
(
unsigned
char
*
)
buf
;
size_t
remaining
=
len
;
...
...
@@ -110,13 +110,12 @@ __socket_xfer (xfer_fn xfer, const int sockfd, const void * buf, const ssize_t l
* data has been sent. Returns the number of bytes sent.
*/
ssize_t
connection_send
(
struct
connection
*
connection
,
const
void
*
buf
,
const
s
size_t
len
)
{
connection_send
_full
(
struct
connection
*
connection
,
const
void
*
buf
,
const
size_t
len
)
{
assert
(
connection
!=
NULL
);
assert
(
buf
!=
NULL
);
assert
(
len
>=
0
);
assert
((
buf
!=
NULL
)
||
(
buf
==
NULL
&&
len
==
0
));
ssize_t
sent
=
__socket_xfer
((
xfer_fn
)
send
,
connection
->
sockfd
,
buf
,
len
);
check_std_error
(
sent
<
0
,
"error sending data to server"
);
ssize_t
sent
=
__socket_xfer
_full
((
xfer_fn
)
send
,
connection
->
sockfd
,
buf
,
len
);
check_std_error
(
sent
<
0
,
"
connection_send_full:
error sending data to server"
);
#ifdef DEBUG
connection
->
sent_bytes
+=
sent
;
...
...
@@ -131,13 +130,31 @@ connection_send (struct connection * connection, const void * buf, const ssize_t
* until all requested data has been received. Returns the number of bytes received.
*/
ssize_t
connection_recv
(
struct
connection
*
connection
,
void
*
buf
,
const
ssize_t
len
)
{
connection_recv_full
(
struct
connection
*
connection
,
void
*
buf
,
const
size_t
len
)
{
assert
(
connection
!=
NULL
);
assert
((
buf
!=
NULL
)
||
(
buf
==
NULL
&&
len
==
0
));
ssize_t
received
=
__socket_xfer_full
((
xfer_fn
)
recv
,
connection
->
sockfd
,
buf
,
len
);
check_std_error
(
received
<
0
,
"connection_recv_full: error receiving data from server"
);
#ifdef DEBUG
connection
->
recv_bytes
+=
received
;
#endif
return
received
;
}
/**
* Receives data from the given connection.
* Returns the number of bytes received.
*/
ssize_t
connection_recv
(
struct
connection
*
connection
,
void
*
buf
,
const
size_t
len
)
{
assert
(
connection
!=
NULL
);
assert
(
buf
!=
NULL
);
assert
(
len
>=
0
);
ssize_t
received
=
__socket_xfer
((
xfer_fn
)
recv
,
connection
->
sockfd
,
buf
,
len
);
check_std_error
(
received
<
0
,
"error receiving data from server"
);
ssize_t
received
=
recv
(
connection
->
sockfd
,
buf
,
len
,
0
);
check_std_error
(
received
<
0
,
"
connection_recv:
error receiving data from server"
);
#ifdef DEBUG
connection
->
recv_bytes
+=
received
;
...
...
@@ -153,7 +170,7 @@ connection_recv (struct connection * connection, void * buf, const ssize_t len)
typedef
ssize_t
(
*
xfer_iov_fn
)
(
int
sockfd
,
struct
iovec
*
iovs
,
int
iov_count
);
static
inline
ssize_t
__socket_xfer_iov
(
__socket_xfer_iov
_full
(
xfer_iov_fn
xfer_iov
,
const
int
sockfd
,
struct
iovec
*
iovs
,
const
int
iov_count
)
{
ssize_t
total
=
0
;
...
...
@@ -198,12 +215,12 @@ __socket_xfer_iov (
* data have been sent. Returns the number of bytes sent.
*/
ssize_t
connection_send_iov
(
struct
connection
*
connection
,
struct
iovec
*
iovs
,
int
iov_count
)
{
connection_send_iov
_full
(
struct
connection
*
connection
,
struct
iovec
*
iovs
,
int
iov_count
)
{
assert
(
connection
!=
NULL
);
assert
(
iovs
!=
NULL
);
assert
(
iov_count
>=
0
);
ssize_t
sent
=
__socket_xfer_iov
((
xfer_iov_fn
)
writev
,
connection
->
sockfd
,
iovs
,
iov_count
);
ssize_t
sent
=
__socket_xfer_iov
_full
((
xfer_iov_fn
)
writev
,
connection
->
sockfd
,
iovs
,
iov_count
);
check_std_error
(
sent
<
0
,
"error sending data to server"
);
#ifdef DEBUG
...
...
@@ -219,13 +236,13 @@ connection_send_iov (struct connection * connection, struct iovec * iovs, int io
* all requested data have been received. Returns the number of bytes received.
*/
ssize_t
connection_recv_iov
(
struct
connection
*
connection
,
struct
iovec
*
iovs
,
int
iov_count
)
{
connection_recv_iov
_full
(
struct
connection
*
connection
,
struct
iovec
*
iovs
,
int
iov_count
)
{
assert
(
connection
!=
NULL
);
assert
(
iovs
!=
NULL
);
assert
(
iov_count
>=
0
);
ssize_t
received
=
__socket_xfer_iov
((
xfer_iov_fn
)
readv
,
connection
->
sockfd
,
iovs
,
iov_count
);
check_std_error
(
received
<
0
,
"error receiving data from server"
);
ssize_t
received
=
__socket_xfer_iov
_full
((
xfer_iov_fn
)
readv
,
connection
->
sockfd
,
iovs
,
iov_count
);
check_std_error
(
received
<
0
,
"
connection_recv_iov_full:
error receiving data from server"
);
#ifdef DEBUG
connection
->
recv_bytes
+=
received
;
...
...
src-disl-agent/connection.h
View file @
a9f11b40
...
...
@@ -43,15 +43,16 @@ struct connection {
struct
connection
*
connection_open
(
struct
addrinfo
*
addr
);
void
connection_close
(
struct
connection
*
connection
);
ssize_t
connection_send
(
struct
connection
*
connection
,
const
void
*
buf
,
const
ssize_t
len
);
ssize_t
connection_recv
(
struct
connection
*
connection
,
void
*
buf
,
const
ssize_t
len
);
ssize_t
connection_send_full
(
struct
connection
*
connection
,
const
void
*
buf
,
const
size_t
len
);
ssize_t
connection_recv_full
(
struct
connection
*
connection
,
void
*
buf
,
const
size_t
len
);
ssize_t
connection_recv
(
struct
connection
*
connection
,
void
*
buf
,
const
size_t
len
);
#ifndef MINGW
#include <sys/uio.h>
ssize_t
connection_send_iov
(
struct
connection
*
connection
,
struct
iovec
*
iovs
,
int
iov_count
);
ssize_t
connection_recv_iov
(
struct
connection
*
connection
,
struct
iovec
*
iovs
,
int
iov_count
);
ssize_t
connection_send_iov
_full
(
struct
connection
*
connection
,
struct
iovec
*
iovs
,
int
iov_count
);
ssize_t
connection_recv_iov
_full
(
struct
connection
*
connection
,
struct
iovec
*
iovs
,
int
iov_count
);
#endif
...
...
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