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
43fa72b7
Commit
43fa72b7
authored
Aug 03, 2009
by
Martin Hurton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
C++ binding uses exceptions to signal failure
parent
cc3755a1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
10 deletions
+73
-10
zmq.hpp
include/zmq.hpp
+73
-10
No files found.
include/zmq.hpp
View file @
43fa72b7
...
...
@@ -23,6 +23,8 @@
#include "zmq.h"
#include <assert.h>
#include <errno.h>
#include <exception>
namespace
zmq
{
...
...
@@ -36,6 +38,38 @@ namespace zmq
message_delimiter
=
1
<<
ZMQ_DELIMITER
};
class
no_memory
:
public
exception
{
virtual
const
char
*
what
()
{
return
"Out of memory"
;
}
};
class
invalid_argument
:
public
exception
{
virtual
const
char
*
what
()
{
return
"Invalid argument"
;
}
};
class
too_many_threads
:
public
exception
{
virtual
const
char
*
what
()
{
return
"Too many threads"
;
}
};
class
address_in_use
:
public
exception
{
virtual
const
char
*
what
()
{
return
"Address in use"
;
}
};
// A message. Caution: Don't change the body of the message once you've
// copied it - the behaviour is undefined. Don't change the body of the
// received message either - other threads may be accessing it in parallel.
...
...
@@ -50,7 +84,10 @@ namespace zmq
inline
message_t
(
size_t
size_
=
0
)
{
int
rc
=
zmq_msg_init_size
(
this
,
size_
);
assert
(
rc
==
0
);
if
(
rc
==
-
1
)
{
assert
(
errno
==
ENOMEM
);
throw
no_memory
();
}
}
// Creates message from the supplied buffer. 0MQ takes care of
...
...
@@ -79,7 +116,10 @@ namespace zmq
int
rc
=
zmq_msg_close
(
this
);
assert
(
rc
==
0
);
rc
=
zmq_msg_init_size
(
this
,
size_
);
assert
(
rc
==
0
);
if
(
rc
==
-
1
)
{
assert
(
errno
==
ENOMEM
);
throw
no_memory
();
}
}
// Same as above, however, the message is rebuilt from the supplied
...
...
@@ -147,7 +187,10 @@ namespace zmq
inline
context_t
(
int
app_threads_
,
int
io_threads_
)
{
ptr
=
zmq_init
(
app_threads_
,
io_threads_
);
assert
(
ptr
);
if
(
ptr
==
NULL
)
{
assert
(
errno
==
EINVAL
);
throw
invalid_argument
();
}
}
inline
~
context_t
()
...
...
@@ -172,7 +215,13 @@ namespace zmq
inline
socket_t
(
context_t
&
context_
,
int
type_
=
0
)
{
ptr
=
zmq_socket
(
context_
.
ptr
,
type_
);
assert
(
ptr
);
if
(
ptr
==
NULL
)
{
assert
(
errno
==
EMFILE
||
errno
==
EINVAL
);
if
(
errno
==
EMFILE
)
throw
too_many_threads
();
else
throw
invalid_argument
();
}
}
inline
~
socket_t
()
...
...
@@ -184,13 +233,25 @@ namespace zmq
inline
void
bind
(
const
char
*
addr_
,
zmq_opts
*
opts_
=
NULL
)
{
int
rc
=
zmq_bind
(
ptr
,
addr_
,
opts_
);
assert
(
rc
==
0
);
if
(
rc
==
-
1
)
{
assert
(
errno
==
EINVAL
||
errno
==
EADDRINUSE
);
if
(
errno
==
EINVAL
)
throw
invalid_argument
();
else
throw
address_in_use
();
}
}
inline
void
connect
(
const
char
*
addr_
,
zmq_opts
*
opts_
=
NULL
)
{
int
rc
=
zmq_connect
(
ptr
,
addr_
,
opts_
);
assert
(
rc
==
0
);
if
(
rc
==
-
1
)
{
assert
(
errno
==
EINVAL
||
errno
==
EADDRINUSE
);
if
(
errno
==
EINVAL
)
throw
invalid_argument
();
else
throw
address_in_use
();
}
}
inline
void
subscribe
(
const
char
*
criteria_
)
...
...
@@ -199,10 +260,11 @@ namespace zmq
assert
(
rc
==
0
);
}
inline
void
send
(
message_t
&
msg_
,
int
flags_
=
0
)
inline
int
send
(
message_t
&
msg_
,
int
flags_
=
0
)
{
int
rc
=
zmq_send
(
ptr
,
&
msg_
,
flags_
);
assert
(
rc
==
0
);
assert
(
rc
==
0
||
(
rc
==
-
1
&&
errno
==
EAGAIN
));
return
rc
;
}
inline
void
flush
()
...
...
@@ -211,10 +273,11 @@ namespace zmq
assert
(
rc
==
0
);
}
inline
void
recv
(
message_t
*
msg_
,
int
flags_
=
0
)
inline
int
recv
(
message_t
*
msg_
,
int
flags_
=
0
)
{
int
rc
=
zmq_recv
(
ptr
,
msg_
,
flags_
);
assert
(
rc
==
0
);
assert
(
rc
==
0
||
(
rc
==
-
1
&&
errno
==
EAGAIN
));
return
rc
;
}
private
:
...
...
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