Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
Project
Project
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
cca67fdd
Commit
cca67fdd
authored
Sep 29, 2015
by
Constantin Rack
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1595 from pijyoi/signaler_failable
create signaler::recv_failable()
parents
52ee7241
596d6e5b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
5 deletions
+57
-5
mailbox.cpp
src/mailbox.cpp
+6
-2
signaler.cpp
src/signaler.cpp
+50
-3
signaler.hpp
src/signaler.hpp
+1
-0
No files found.
src/mailbox.cpp
View file @
cca67fdd
...
...
@@ -77,14 +77,18 @@ int zmq::mailbox_t::recv (command_t *cmd_, int timeout_)
}
// Wait for signal from the command sender.
const
int
rc
=
signaler
.
wait
(
timeout_
);
int
rc
=
signaler
.
wait
(
timeout_
);
if
(
rc
==
-
1
)
{
errno_assert
(
errno
==
EAGAIN
||
errno
==
EINTR
);
return
-
1
;
}
// Receive the signal.
signaler
.
recv
();
rc
=
signaler
.
recv_failable
();
if
(
rc
==
-
1
)
{
errno_assert
(
errno
==
EAGAIN
);
return
-
1
;
}
// Switch into active state.
active
=
true
;
...
...
src/signaler.cpp
View file @
cca67fdd
...
...
@@ -284,6 +284,38 @@ int zmq::signaler_t::wait (int timeout_)
}
void
zmq
::
signaler_t
::
recv
()
{
// Attempt to read a signal.
#if defined ZMQ_HAVE_EVENTFD
uint64_t
dummy
;
ssize_t
sz
=
read
(
r
,
&
dummy
,
sizeof
(
dummy
));
errno_assert
(
sz
==
sizeof
(
dummy
));
// If we accidentally grabbed the next signal(s) along with the current
// one, return it back to the eventfd object.
if
(
unlikely
(
dummy
>
1
))
{
const
uint64_t
inc
=
dummy
-
1
;
ssize_t
sz2
=
write
(
w
,
&
inc
,
sizeof
(
inc
));
errno_assert
(
sz2
==
sizeof
(
inc
));
return
;
}
zmq_assert
(
dummy
==
1
);
#else
unsigned
char
dummy
;
#if defined ZMQ_HAVE_WINDOWS
int
nbytes
=
::
recv
(
r
,
(
char
*
)
&
dummy
,
sizeof
(
dummy
),
0
);
wsa_assert
(
nbytes
!=
SOCKET_ERROR
);
#else
ssize_t
nbytes
=
::
recv
(
r
,
&
dummy
,
sizeof
(
dummy
),
0
);
errno_assert
(
nbytes
>=
0
);
#endif
zmq_assert
(
nbytes
==
sizeof
(
dummy
));
zmq_assert
(
dummy
==
0
);
#endif
}
int
zmq
::
signaler_t
::
recv_failable
()
{
// Attempt to read a signal.
#if defined ZMQ_HAVE_EVENTFD
...
...
@@ -291,6 +323,7 @@ void zmq::signaler_t::recv ()
ssize_t
sz
=
read
(
r
,
&
dummy
,
sizeof
(
dummy
));
if
(
sz
==
-
1
)
{
errno_assert
(
errno
==
EAGAIN
);
return
-
1
;
}
else
{
errno_assert
(
sz
==
sizeof
(
dummy
));
...
...
@@ -301,7 +334,7 @@ void zmq::signaler_t::recv ()
const
uint64_t
inc
=
dummy
-
1
;
ssize_t
sz2
=
write
(
w
,
&
inc
,
sizeof
(
inc
));
errno_assert
(
sz2
==
sizeof
(
inc
));
return
;
return
0
;
}
zmq_assert
(
dummy
==
1
);
...
...
@@ -310,14 +343,28 @@ void zmq::signaler_t::recv ()
unsigned
char
dummy
;
#if defined ZMQ_HAVE_WINDOWS
int
nbytes
=
::
recv
(
r
,
(
char
*
)
&
dummy
,
sizeof
(
dummy
),
0
);
wsa_assert
(
nbytes
!=
SOCKET_ERROR
);
if
(
nbytes
==
SOCKET_ERROR
)
{
const
int
last_error
=
WSAGetLastError
();
if
(
last_error
==
WSAEWOULDBLOCK
)
{
errno
=
EAGAIN
;
return
-
1
;
}
wsa_assert
(
last_error
==
WSAEWOULDBLOCK
);
}
#else
ssize_t
nbytes
=
::
recv
(
r
,
&
dummy
,
sizeof
(
dummy
),
0
);
errno_assert
(
nbytes
>=
0
);
if
(
nbytes
==
-
1
)
{
if
(
errno
==
EAGAIN
||
errno
==
EWOULDBLOCK
||
errno
==
EINTR
)
{
errno
=
EAGAIN
;
return
-
1
;
}
errno_assert
(
errno
==
EAGAIN
||
errno
==
EWOULDBLOCK
||
errno
==
EINTR
);
}
#endif
zmq_assert
(
nbytes
==
sizeof
(
dummy
));
zmq_assert
(
dummy
==
0
);
#endif
return
0
;
}
#ifdef HAVE_FORK
...
...
src/signaler.hpp
View file @
cca67fdd
...
...
@@ -55,6 +55,7 @@ namespace zmq
void
send
();
int
wait
(
int
timeout_
);
void
recv
();
int
recv_failable
();
#ifdef HAVE_FORK
// close the file descriptors in a forked child process so that they
...
...
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