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
656258c1
Commit
656258c1
authored
Mar 08, 2013
by
Pieter Hintjens
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #527 from guidog/master
Simplified zmq_event_t structure.
parents
068909f4
21eeb03b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
132 deletions
+52
-132
zmq.h
include/zmq.h
+4
-44
socket_base.cpp
src/socket_base.cpp
+30
-30
zmq.cpp
src/zmq.cpp
+3
-34
test_monitor.cpp
tests/test_monitor.cpp
+15
-24
No files found.
include/zmq.h
View file @
656258c1
...
...
@@ -294,51 +294,11 @@ ZMQ_EXPORT int zmq_msg_set (zmq_msg_t *msg, int option, int optval);
ZMQ_EVENT_ACCEPT_FAILED | ZMQ_EVENT_CLOSED | \
ZMQ_EVENT_CLOSE_FAILED | ZMQ_EVENT_DISCONNECTED )
/* Socket event data
(union member per event)
*/
/* Socket event data */
typedef
struct
{
int
event
;
union
{
struct
{
char
*
addr
;
int
fd
;
}
connected
;
struct
{
char
*
addr
;
int
err
;
}
connect_delayed
;
struct
{
char
*
addr
;
int
interval
;
}
connect_retried
;
struct
{
char
*
addr
;
int
fd
;
}
listening
;
struct
{
char
*
addr
;
int
err
;
}
bind_failed
;
struct
{
char
*
addr
;
int
fd
;
}
accepted
;
struct
{
char
*
addr
;
int
err
;
}
accept_failed
;
struct
{
char
*
addr
;
int
fd
;
}
closed
;
struct
{
char
*
addr
;
int
err
;
}
close_failed
;
struct
{
char
*
addr
;
int
fd
;
}
disconnected
;
}
data
;
unsigned
int
event
;
// id of the event as bitfield
char
*
addr
;
// endpoint affected as c string
int
value
;
// value is either error code, fd or reconnect interval
}
zmq_event_t
;
ZMQ_EXPORT
void
*
zmq_socket
(
void
*
,
int
type
);
...
...
src/socket_base.cpp
View file @
656258c1
...
...
@@ -1091,9 +1091,9 @@ void zmq::socket_base_t::event_connected (std::string &addr_, int fd_)
if
(
monitor_events
&
ZMQ_EVENT_CONNECTED
)
{
zmq_event_t
event
;
event
.
event
=
ZMQ_EVENT_CONNECTED
;
event
.
data
.
connected
.
addr
=
(
char
*
)
malloc
(
addr_
.
size
()
+
1
);
copy_monitor_address
(
event
.
data
.
connected
.
addr
,
addr_
);
event
.
data
.
connected
.
fd
=
fd_
;
event
.
addr
=
(
char
*
)
malloc
(
addr_
.
size
()
+
1
);
copy_monitor_address
(
event
.
addr
,
addr_
);
event
.
value
=
fd_
;
monitor_event
(
event
);
}
}
...
...
@@ -1103,9 +1103,9 @@ void zmq::socket_base_t::event_connect_delayed (std::string &addr_, int err_)
if
(
monitor_events
&
ZMQ_EVENT_CONNECT_DELAYED
)
{
zmq_event_t
event
;
event
.
event
=
ZMQ_EVENT_CONNECT_DELAYED
;
event
.
data
.
connect_delayed
.
addr
=
(
char
*
)
malloc
(
addr_
.
size
()
+
1
);
copy_monitor_address
(
event
.
data
.
connect_delayed
.
addr
,
addr_
);
event
.
data
.
connect_delayed
.
err
=
err_
;
event
.
addr
=
(
char
*
)
malloc
(
addr_
.
size
()
+
1
);
copy_monitor_address
(
event
.
addr
,
addr_
);
event
.
value
=
err_
;
monitor_event
(
event
);
}
}
...
...
@@ -1115,9 +1115,9 @@ void zmq::socket_base_t::event_connect_retried (std::string &addr_, int interval
if
(
monitor_events
&
ZMQ_EVENT_CONNECT_RETRIED
)
{
zmq_event_t
event
;
event
.
event
=
ZMQ_EVENT_CONNECT_RETRIED
;
event
.
data
.
connect_retried
.
addr
=
(
char
*
)
malloc
(
addr_
.
size
()
+
1
);
copy_monitor_address
(
event
.
data
.
connect_retried
.
addr
,
addr_
);
event
.
data
.
connect_retried
.
interval
=
interval_
;
event
.
addr
=
(
char
*
)
malloc
(
addr_
.
size
()
+
1
);
copy_monitor_address
(
event
.
addr
,
addr_
);
event
.
value
=
interval_
;
monitor_event
(
event
);
}
}
...
...
@@ -1127,9 +1127,9 @@ void zmq::socket_base_t::event_listening (std::string &addr_, int fd_)
if
(
monitor_events
&
ZMQ_EVENT_LISTENING
)
{
zmq_event_t
event
;
event
.
event
=
ZMQ_EVENT_LISTENING
;
event
.
data
.
listening
.
addr
=
(
char
*
)
malloc
(
addr_
.
size
()
+
1
);
copy_monitor_address
(
event
.
data
.
listening
.
addr
,
addr_
);
event
.
data
.
listening
.
fd
=
fd_
;
event
.
addr
=
(
char
*
)
malloc
(
addr_
.
size
()
+
1
);
copy_monitor_address
(
event
.
addr
,
addr_
);
event
.
value
=
fd_
;
monitor_event
(
event
);
}
}
...
...
@@ -1139,9 +1139,9 @@ void zmq::socket_base_t::event_bind_failed (std::string &addr_, int err_)
if
(
monitor_events
&
ZMQ_EVENT_BIND_FAILED
)
{
zmq_event_t
event
;
event
.
event
=
ZMQ_EVENT_BIND_FAILED
;
event
.
data
.
bind_failed
.
addr
=
(
char
*
)
malloc
(
addr_
.
size
()
+
1
);
copy_monitor_address
(
event
.
data
.
bind_failed
.
addr
,
addr_
);
event
.
data
.
bind_failed
.
err
=
err_
;
event
.
addr
=
(
char
*
)
malloc
(
addr_
.
size
()
+
1
);
copy_monitor_address
(
event
.
addr
,
addr_
);
event
.
value
=
err_
;
monitor_event
(
event
);
}
}
...
...
@@ -1151,9 +1151,9 @@ void zmq::socket_base_t::event_accepted (std::string &addr_, int fd_)
if
(
monitor_events
&
ZMQ_EVENT_ACCEPTED
)
{
zmq_event_t
event
;
event
.
event
=
ZMQ_EVENT_ACCEPTED
;
event
.
data
.
accepted
.
addr
=
(
char
*
)
malloc
(
addr_
.
size
()
+
1
);
copy_monitor_address
(
event
.
data
.
accepted
.
addr
,
addr_
);
event
.
data
.
accepted
.
fd
=
fd_
;
event
.
addr
=
(
char
*
)
malloc
(
addr_
.
size
()
+
1
);
copy_monitor_address
(
event
.
addr
,
addr_
);
event
.
value
=
fd_
;
monitor_event
(
event
);
}
}
...
...
@@ -1163,9 +1163,9 @@ void zmq::socket_base_t::event_accept_failed (std::string &addr_, int err_)
if
(
monitor_events
&
ZMQ_EVENT_ACCEPT_FAILED
)
{
zmq_event_t
event
;
event
.
event
=
ZMQ_EVENT_ACCEPT_FAILED
;
event
.
data
.
accept_failed
.
addr
=
(
char
*
)
malloc
(
addr_
.
size
()
+
1
);
copy_monitor_address
(
event
.
data
.
accept_failed
.
addr
,
addr_
);
event
.
data
.
accept_failed
.
err
=
err_
;
event
.
addr
=
(
char
*
)
malloc
(
addr_
.
size
()
+
1
);
copy_monitor_address
(
event
.
addr
,
addr_
);
event
.
value
=
err_
;
monitor_event
(
event
);
}
}
...
...
@@ -1175,9 +1175,9 @@ void zmq::socket_base_t::event_closed (std::string &addr_, int fd_)
if
(
monitor_events
&
ZMQ_EVENT_CLOSED
)
{
zmq_event_t
event
;
event
.
event
=
ZMQ_EVENT_CLOSED
;
event
.
data
.
closed
.
addr
=
(
char
*
)
malloc
(
addr_
.
size
()
+
1
);
copy_monitor_address
(
event
.
data
.
closed
.
addr
,
addr_
);
event
.
data
.
closed
.
fd
=
fd_
;
event
.
addr
=
(
char
*
)
malloc
(
addr_
.
size
()
+
1
);
copy_monitor_address
(
event
.
addr
,
addr_
);
event
.
value
=
fd_
;
monitor_event
(
event
);
}
}
...
...
@@ -1187,9 +1187,9 @@ void zmq::socket_base_t::event_close_failed (std::string &addr_, int err_)
if
(
monitor_events
&
ZMQ_EVENT_CLOSE_FAILED
)
{
zmq_event_t
event
;
event
.
event
=
ZMQ_EVENT_CLOSE_FAILED
;
event
.
data
.
close_failed
.
addr
=
(
char
*
)
malloc
(
addr_
.
size
()
+
1
);
copy_monitor_address
(
event
.
data
.
close_failed
.
addr
,
addr_
);
event
.
data
.
close_failed
.
err
=
err_
;
event
.
addr
=
(
char
*
)
malloc
(
addr_
.
size
()
+
1
);
copy_monitor_address
(
event
.
addr
,
addr_
);
event
.
value
=
err_
;
monitor_event
(
event
);
}
}
...
...
@@ -1199,9 +1199,9 @@ void zmq::socket_base_t::event_disconnected (std::string &addr_, int fd_)
if
(
monitor_events
&
ZMQ_EVENT_DISCONNECTED
)
{
zmq_event_t
event
;
event
.
event
=
ZMQ_EVENT_DISCONNECTED
;
event
.
data
.
disconnected
.
addr
=
(
char
*
)
malloc
(
addr_
.
size
()
+
1
);
copy_monitor_address
(
event
.
data
.
disconnected
.
addr
,
addr_
);
event
.
data
.
disconnected
.
fd
=
fd_
;
event
.
addr
=
(
char
*
)
malloc
(
addr_
.
size
()
+
1
);
copy_monitor_address
(
event
.
addr
,
addr_
);
event
.
value
=
fd_
;
monitor_event
(
event
);
}
}
...
...
src/zmq.cpp
View file @
656258c1
...
...
@@ -1004,39 +1004,8 @@ int zmq_device (int /* type */, void *frontend_, void *backend_)
void
zmq_free_event
(
void
*
event_data
,
void
*
/* hint */
)
{
zmq_event_t
*
event
=
(
zmq_event_t
*
)
event_data
;
switch
(
event
->
event
)
{
case
ZMQ_EVENT_CONNECTED
:
free
(
event
->
data
.
connected
.
addr
);
break
;
case
ZMQ_EVENT_CONNECT_DELAYED
:
free
(
event
->
data
.
connect_delayed
.
addr
);
break
;
case
ZMQ_EVENT_CONNECT_RETRIED
:
free
(
event
->
data
.
connect_retried
.
addr
);
break
;
case
ZMQ_EVENT_LISTENING
:
free
(
event
->
data
.
listening
.
addr
);
break
;
case
ZMQ_EVENT_BIND_FAILED
:
free
(
event
->
data
.
bind_failed
.
addr
);
break
;
case
ZMQ_EVENT_ACCEPTED
:
free
(
event
->
data
.
accepted
.
addr
);
break
;
case
ZMQ_EVENT_ACCEPT_FAILED
:
free
(
event
->
data
.
accept_failed
.
addr
);
break
;
case
ZMQ_EVENT_CLOSED
:
free
(
event
->
data
.
closed
.
addr
);
break
;
case
ZMQ_EVENT_CLOSE_FAILED
:
free
(
event
->
data
.
close_failed
.
addr
);
break
;
case
ZMQ_EVENT_DISCONNECTED
:
free
(
event
->
data
.
disconnected
.
addr
);
break
;
}
const
zmq_event_t
*
event
=
(
zmq_event_t
*
)
event_data
;
free
(
event
->
addr
);
free
(
event_data
);
}
tests/test_monitor.cpp
View file @
656258c1
...
...
@@ -53,31 +53,27 @@ static void *req_socket_monitor (void *ctx)
assert
(
rc
!=
-
1
);
memcpy
(
&
event
,
zmq_msg_data
(
&
msg
),
sizeof
(
event
));
assert
(
!
strcmp
(
event
.
addr
,
addr
));
switch
(
event
.
event
)
{
case
ZMQ_EVENT_CONNECTED
:
assert
(
event
.
data
.
connected
.
fd
>
0
);
assert
(
!
strcmp
(
event
.
data
.
connected
.
addr
,
addr
));
assert
(
event
.
value
>
0
);
req_socket_events
|=
ZMQ_EVENT_CONNECTED
;
req2_socket_events
|=
ZMQ_EVENT_CONNECTED
;
break
;
case
ZMQ_EVENT_CONNECT_DELAYED
:
assert
(
event
.
data
.
connect_delayed
.
err
!=
0
);
assert
(
!
strcmp
(
event
.
data
.
connect_delayed
.
addr
,
addr
));
assert
(
event
.
value
!=
0
);
req_socket_events
|=
ZMQ_EVENT_CONNECT_DELAYED
;
break
;
case
ZMQ_EVENT_CLOSE_FAILED
:
assert
(
event
.
data
.
close_failed
.
err
!=
0
);
assert
(
!
strcmp
(
event
.
data
.
close_failed
.
addr
,
addr
));
assert
(
event
.
value
!=
0
);
req_socket_events
|=
ZMQ_EVENT_CLOSE_FAILED
;
break
;
case
ZMQ_EVENT_CLOSED
:
assert
(
event
.
data
.
closed
.
fd
!=
0
);
assert
(
!
strcmp
(
event
.
data
.
closed
.
addr
,
addr
));
assert
(
event
.
value
!=
0
);
req_socket_events
|=
ZMQ_EVENT_CLOSED
;
break
;
case
ZMQ_EVENT_DISCONNECTED
:
assert
(
event
.
data
.
disconnected
.
fd
!=
0
);
assert
(
!
strcmp
(
event
.
data
.
disconnected
.
addr
,
addr
));
assert
(
event
.
value
!=
0
);
req_socket_events
|=
ZMQ_EVENT_DISCONNECTED
;
break
;
}
...
...
@@ -106,15 +102,14 @@ static void *req2_socket_monitor (void *ctx)
assert
(
rc
!=
-
1
);
memcpy
(
&
event
,
zmq_msg_data
(
&
msg
),
sizeof
(
event
));
assert
(
!
strcmp
(
event
.
addr
,
addr
));
switch
(
event
.
event
)
{
case
ZMQ_EVENT_CONNECTED
:
assert
(
event
.
data
.
connected
.
fd
>
0
);
assert
(
!
strcmp
(
event
.
data
.
connected
.
addr
,
addr
));
assert
(
event
.
value
>
0
);
req2_socket_events
|=
ZMQ_EVENT_CONNECTED
;
break
;
case
ZMQ_EVENT_CLOSED
:
assert
(
event
.
data
.
closed
.
fd
!=
0
);
assert
(
!
strcmp
(
event
.
data
.
closed
.
addr
,
addr
));
assert
(
event
.
value
!=
0
);
req2_socket_events
|=
ZMQ_EVENT_CLOSED
;
break
;
}
...
...
@@ -143,30 +138,26 @@ static void *rep_socket_monitor (void *ctx)
assert
(
rc
!=
-
1
);
memcpy
(
&
event
,
zmq_msg_data
(
&
msg
),
sizeof
(
event
));
assert
(
!
strcmp
(
event
.
addr
,
addr
));
switch
(
event
.
event
)
{
case
ZMQ_EVENT_LISTENING
:
assert
(
event
.
data
.
listening
.
fd
>
0
);
assert
(
!
strcmp
(
event
.
data
.
listening
.
addr
,
addr
));
assert
(
event
.
value
>
0
);
rep_socket_events
|=
ZMQ_EVENT_LISTENING
;
break
;
case
ZMQ_EVENT_ACCEPTED
:
assert
(
event
.
data
.
accepted
.
fd
>
0
);
assert
(
!
strcmp
(
event
.
data
.
accepted
.
addr
,
addr
));
assert
(
event
.
value
>
0
);
rep_socket_events
|=
ZMQ_EVENT_ACCEPTED
;
break
;
case
ZMQ_EVENT_CLOSE_FAILED
:
assert
(
event
.
data
.
close_failed
.
err
!=
0
);
assert
(
!
strcmp
(
event
.
data
.
close_failed
.
addr
,
addr
));
assert
(
event
.
value
!=
0
);
rep_socket_events
|=
ZMQ_EVENT_CLOSE_FAILED
;
break
;
case
ZMQ_EVENT_CLOSED
:
assert
(
event
.
data
.
closed
.
fd
!=
0
);
assert
(
!
strcmp
(
event
.
data
.
closed
.
addr
,
addr
));
assert
(
event
.
value
!=
0
);
rep_socket_events
|=
ZMQ_EVENT_CLOSED
;
break
;
case
ZMQ_EVENT_DISCONNECTED
:
assert
(
event
.
data
.
disconnected
.
fd
!=
0
);
assert
(
!
strcmp
(
event
.
data
.
disconnected
.
addr
,
addr
));
assert
(
event
.
value
!=
0
);
rep_socket_events
|=
ZMQ_EVENT_DISCONNECTED
;
break
;
}
...
...
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