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
498dc379
Commit
498dc379
authored
Sep 06, 2013
by
Martin Hurton
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #645 from hintjens/master
Updated libzmq to match RFCs
parents
1f037109
4c753060
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
176 additions
and
281 deletions
+176
-281
.gitignore
.gitignore
+1
-0
CMakeLists.txt
CMakeLists.txt
+1
-1
curve_client.cpp
src/curve_client.cpp
+12
-12
curve_client.hpp
src/curve_client.hpp
+4
-4
curve_server.cpp
src/curve_server.cpp
+12
-12
curve_server.hpp
src/curve_server.hpp
+4
-4
mechanism.hpp
src/mechanism.hpp
+4
-4
msg.hpp
src/msg.hpp
+2
-1
null_mechanism.cpp
src/null_mechanism.cpp
+4
-4
null_mechanism.hpp
src/null_mechanism.hpp
+2
-2
plain_mechanism.cpp
src/plain_mechanism.cpp
+34
-32
plain_mechanism.hpp
src/plain_mechanism.hpp
+10
-10
stream_engine.cpp
src/stream_engine.cpp
+9
-11
stream_engine.hpp
src/stream_engine.hpp
+4
-4
v2_decoder.cpp
src/v2_decoder.cpp
+2
-0
v2_encoder.cpp
src/v2_encoder.cpp
+2
-0
v2_protocol.hpp
src/v2_protocol.hpp
+2
-1
Makefile.am
tests/Makefile.am
+3
-5
test_raw_sock.cpp
tests/test_raw_sock.cpp
+0
-166
test_security_curve.cpp
tests/test_security_curve.cpp
+2
-2
test_stream.cpp
tests/test_stream.cpp
+10
-5
test_system.cpp
tests/test_system.cpp
+51
-0
curve_keygen.c
tools/curve_keygen.c
+1
-1
No files found.
.gitignore
View file @
498dc379
...
...
@@ -23,6 +23,7 @@ autom4te.cache
tools/curve_keygen.o
tools/curve_keygen
tests/test_term_endpoint
tests/test_system
tests/test_monitor
tests/test_last_endpoint
tests/test_pair_inproc
...
...
CMakeLists.txt
View file @
498dc379
...
...
@@ -578,6 +578,7 @@ endif()
enable_testing
()
set
(
tests
test_system
test_connect_delay
test_connect_resolve
test_ctx_options
...
...
@@ -612,7 +613,6 @@ if(NOT WIN32)
list
(
APPEND tests
test_monitor
test_pair_ipc
test_raw_sock
test_reqrep_ipc
test_stream
)
endif
()
...
...
src/curve_client.cpp
View file @
498dc379
...
...
@@ -50,18 +50,18 @@ zmq::curve_client_t::~curve_client_t ()
{
}
int
zmq
::
curve_client_t
::
next_handshake_
message
(
msg_t
*
msg_
)
int
zmq
::
curve_client_t
::
next_handshake_
command
(
msg_t
*
msg_
)
{
int
rc
=
0
;
switch
(
state
)
{
case
send_hello
:
rc
=
hello_msg
(
msg_
);
rc
=
produce_hello
(
msg_
);
if
(
rc
==
0
)
state
=
expect_welcome
;
break
;
case
send_initiate
:
rc
=
initiate_msg
(
msg_
);
rc
=
produce_initiate
(
msg_
);
if
(
rc
==
0
)
state
=
expect_ready
;
break
;
...
...
@@ -72,7 +72,7 @@ int zmq::curve_client_t::next_handshake_message (msg_t *msg_)
return
rc
;
}
int
zmq
::
curve_client_t
::
process_handshake_
message
(
msg_t
*
msg_
)
int
zmq
::
curve_client_t
::
process_handshake_
command
(
msg_t
*
msg_
)
{
int
rc
=
0
;
...
...
@@ -138,7 +138,7 @@ int zmq::curve_client_t::encode (msg_t *msg_)
uint8_t
*
message
=
static_cast
<
uint8_t
*>
(
msg_
->
data
());
memcpy
(
message
,
"
MESSAGE
\0
"
,
8
);
memcpy
(
message
,
"
\x07
MESSAGE
"
,
8
);
memcpy
(
message
+
8
,
&
cn_nonce
,
8
);
memcpy
(
message
+
16
,
message_box
+
crypto_box_BOXZEROBYTES
,
mlen
-
crypto_box_BOXZEROBYTES
);
...
...
@@ -161,7 +161,7 @@ int zmq::curve_client_t::decode (msg_t *msg_)
}
const
uint8_t
*
message
=
static_cast
<
uint8_t
*>
(
msg_
->
data
());
if
(
memcmp
(
message
,
"
MESSAGE
\0
"
,
8
))
{
if
(
memcmp
(
message
,
"
\x07
MESSAGE
"
,
8
))
{
errno
=
EPROTO
;
return
-
1
;
}
...
...
@@ -213,7 +213,7 @@ bool zmq::curve_client_t::is_handshake_complete () const
return
state
==
connected
;
}
int
zmq
::
curve_client_t
::
hello_msg
(
msg_t
*
msg_
)
int
zmq
::
curve_client_t
::
produce_hello
(
msg_t
*
msg_
)
{
uint8_t
hello_nonce
[
crypto_box_NONCEBYTES
];
uint8_t
hello_plaintext
[
crypto_box_ZEROBYTES
+
64
];
...
...
@@ -235,7 +235,7 @@ int zmq::curve_client_t::hello_msg (msg_t *msg_)
errno_assert
(
rc
==
0
);
uint8_t
*
hello
=
static_cast
<
uint8_t
*>
(
msg_
->
data
());
memcpy
(
hello
,
"
HELLO
\0
"
,
6
);
memcpy
(
hello
,
"
\x05
HELLO
"
,
6
);
// CurveZMQ major and minor version numbers
memcpy
(
hello
+
6
,
"
\1\0
"
,
2
);
// Anti-amplification padding
...
...
@@ -260,7 +260,7 @@ int zmq::curve_client_t::process_welcome (msg_t *msg_)
}
const
uint8_t
*
welcome
=
static_cast
<
uint8_t
*>
(
msg_
->
data
());
if
(
memcmp
(
welcome
,
"
WELCOME
\0
"
,
8
))
{
if
(
memcmp
(
welcome
,
"
\x07
WELCOME
"
,
8
))
{
errno
=
EPROTO
;
return
-
1
;
}
...
...
@@ -294,7 +294,7 @@ int zmq::curve_client_t::process_welcome (msg_t *msg_)
return
0
;
}
int
zmq
::
curve_client_t
::
initiate_msg
(
msg_t
*
msg_
)
int
zmq
::
curve_client_t
::
produce_initiate
(
msg_t
*
msg_
)
{
uint8_t
vouch_nonce
[
crypto_box_NONCEBYTES
];
uint8_t
vouch_plaintext
[
crypto_box_ZEROBYTES
+
32
];
...
...
@@ -351,7 +351,7 @@ int zmq::curve_client_t::initiate_msg (msg_t *msg_)
uint8_t
*
initiate
=
static_cast
<
uint8_t
*>
(
msg_
->
data
());
memcpy
(
initiate
,
"
INITIATE
\0
"
,
9
);
memcpy
(
initiate
,
"
\x08
INITIATE
"
,
9
);
// Cookie provided by the server in the WELCOME command
memcpy
(
initiate
+
9
,
cn_cookie
,
96
);
// Short nonce, prefixed by "CurveZMQINITIATE"
...
...
@@ -373,7 +373,7 @@ int zmq::curve_client_t::process_ready (msg_t *msg_)
}
const
uint8_t
*
ready
=
static_cast
<
uint8_t
*>
(
msg_
->
data
());
if
(
memcmp
(
ready
,
"
READY
\0
"
,
6
))
{
if
(
memcmp
(
ready
,
"
\x05
READY
"
,
6
))
{
errno
=
EPROTO
;
return
-
1
;
}
...
...
src/curve_client.hpp
View file @
498dc379
...
...
@@ -50,8 +50,8 @@ namespace zmq
virtual
~
curve_client_t
();
// mechanism implementation
virtual
int
next_handshake_
message
(
msg_t
*
msg_
);
virtual
int
process_handshake_
message
(
msg_t
*
msg_
);
virtual
int
next_handshake_
command
(
msg_t
*
msg_
);
virtual
int
process_handshake_
command
(
msg_t
*
msg_
);
virtual
int
encode
(
msg_t
*
msg_
);
virtual
int
decode
(
msg_t
*
msg_
);
virtual
bool
is_handshake_complete
()
const
;
...
...
@@ -96,9 +96,9 @@ namespace zmq
// Nonce
uint64_t
cn_nonce
;
int
hello_msg
(
msg_t
*
msg_
);
int
produce_hello
(
msg_t
*
msg_
);
int
process_welcome
(
msg_t
*
msg_
);
int
initiate_msg
(
msg_t
*
msg_
);
int
produce_initiate
(
msg_t
*
msg_
);
int
process_ready
(
msg_t
*
msg_
);
};
...
...
src/curve_server.cpp
View file @
498dc379
...
...
@@ -54,18 +54,18 @@ zmq::curve_server_t::~curve_server_t ()
{
}
int
zmq
::
curve_server_t
::
next_handshake_
message
(
msg_t
*
msg_
)
int
zmq
::
curve_server_t
::
next_handshake_
command
(
msg_t
*
msg_
)
{
int
rc
=
0
;
switch
(
state
)
{
case
send_welcome
:
rc
=
welcome_msg
(
msg_
);
rc
=
produce_welcome
(
msg_
);
if
(
rc
==
0
)
state
=
expect_initiate
;
break
;
case
send_ready
:
rc
=
ready_msg
(
msg_
);
rc
=
produce_ready
(
msg_
);
if
(
rc
==
0
)
state
=
connected
;
break
;
...
...
@@ -77,7 +77,7 @@ int zmq::curve_server_t::next_handshake_message (msg_t *msg_)
return
rc
;
}
int
zmq
::
curve_server_t
::
process_handshake_
message
(
msg_t
*
msg_
)
int
zmq
::
curve_server_t
::
process_handshake_
command
(
msg_t
*
msg_
)
{
int
rc
=
0
;
...
...
@@ -143,7 +143,7 @@ int zmq::curve_server_t::encode (msg_t *msg_)
uint8_t
*
message
=
static_cast
<
uint8_t
*>
(
msg_
->
data
());
memcpy
(
message
,
"
MESSAGE
\0
"
,
8
);
memcpy
(
message
,
"
\x07
MESSAGE
"
,
8
);
memcpy
(
message
+
8
,
&
cn_nonce
,
8
);
memcpy
(
message
+
16
,
message_box
+
crypto_box_BOXZEROBYTES
,
mlen
-
crypto_box_BOXZEROBYTES
);
...
...
@@ -166,7 +166,7 @@ int zmq::curve_server_t::decode (msg_t *msg_)
}
const
uint8_t
*
message
=
static_cast
<
uint8_t
*>
(
msg_
->
data
());
if
(
memcmp
(
message
,
"
MESSAGE
\0
"
,
8
))
{
if
(
memcmp
(
message
,
"
\x07
MESSAGE
"
,
8
))
{
errno
=
EPROTO
;
return
-
1
;
}
...
...
@@ -238,7 +238,7 @@ int zmq::curve_server_t::process_hello (msg_t *msg_)
}
const
uint8_t
*
const
hello
=
static_cast
<
uint8_t
*>
(
msg_
->
data
());
if
(
memcmp
(
hello
,
"
HELLO
\0
"
,
6
))
{
if
(
memcmp
(
hello
,
"
\x05
HELLO
"
,
6
))
{
errno
=
EPROTO
;
return
-
1
;
}
...
...
@@ -276,7 +276,7 @@ int zmq::curve_server_t::process_hello (msg_t *msg_)
return
rc
;
}
int
zmq
::
curve_server_t
::
welcome_msg
(
msg_t
*
msg_
)
int
zmq
::
curve_server_t
::
produce_welcome
(
msg_t
*
msg_
)
{
uint8_t
cookie_nonce
[
crypto_secretbox_NONCEBYTES
];
uint8_t
cookie_plaintext
[
crypto_secretbox_ZEROBYTES
+
64
];
...
...
@@ -329,7 +329,7 @@ int zmq::curve_server_t::welcome_msg (msg_t *msg_)
errno_assert
(
rc
==
0
);
uint8_t
*
const
welcome
=
static_cast
<
uint8_t
*>
(
msg_
->
data
());
memcpy
(
welcome
,
"
WELCOME
\0
"
,
8
);
memcpy
(
welcome
,
"
\x07
WELCOME
"
,
8
);
memcpy
(
welcome
+
8
,
welcome_nonce
+
8
,
16
);
memcpy
(
welcome
+
24
,
welcome_ciphertext
+
crypto_box_BOXZEROBYTES
,
144
);
...
...
@@ -344,7 +344,7 @@ int zmq::curve_server_t::process_initiate (msg_t *msg_)
}
const
uint8_t
*
initiate
=
static_cast
<
uint8_t
*>
(
msg_
->
data
());
if
(
memcmp
(
initiate
,
"
INITIATE
\0
"
,
9
))
{
if
(
memcmp
(
initiate
,
"
\x08
INITIATE
"
,
9
))
{
errno
=
EPROTO
;
return
-
1
;
}
...
...
@@ -447,7 +447,7 @@ int zmq::curve_server_t::process_initiate (msg_t *msg_)
clen
-
crypto_box_ZEROBYTES
-
96
);
}
int
zmq
::
curve_server_t
::
ready_msg
(
msg_t
*
msg_
)
int
zmq
::
curve_server_t
::
produce_ready
(
msg_t
*
msg_
)
{
uint8_t
ready_nonce
[
crypto_box_NONCEBYTES
];
uint8_t
ready_plaintext
[
crypto_box_ZEROBYTES
+
256
];
...
...
@@ -482,7 +482,7 @@ int zmq::curve_server_t::ready_msg (msg_t *msg_)
uint8_t
*
ready
=
static_cast
<
uint8_t
*>
(
msg_
->
data
());
memcpy
(
ready
,
"
READY
\0
"
,
6
);
memcpy
(
ready
,
"
\x05
READY
"
,
6
);
// Short nonce, prefixed by "CurveZMQREADY---"
memcpy
(
ready
+
6
,
&
cn_nonce
,
8
);
// Box [metadata](S'->C')
...
...
src/curve_server.hpp
View file @
498dc379
...
...
@@ -55,8 +55,8 @@ namespace zmq
virtual
~
curve_server_t
();
// mechanism implementation
virtual
int
next_handshake_
message
(
msg_t
*
msg_
);
virtual
int
process_handshake_
message
(
msg_t
*
msg_
);
virtual
int
next_handshake_
command
(
msg_t
*
msg_
);
virtual
int
process_handshake_
command
(
msg_t
*
msg_
);
virtual
int
encode
(
msg_t
*
msg_
);
virtual
int
decode
(
msg_t
*
msg_
);
virtual
int
zap_msg_available
();
...
...
@@ -104,9 +104,9 @@ namespace zmq
uint8_t
cn_precom
[
crypto_box_BEFORENMBYTES
];
int
process_hello
(
msg_t
*
msg_
);
int
welcome_msg
(
msg_t
*
msg_
);
int
produce_welcome
(
msg_t
*
msg_
);
int
process_initiate
(
msg_t
*
msg_
);
int
ready_msg
(
msg_t
*
msg_
);
int
produce_ready
(
msg_t
*
msg_
);
void
send_zap_request
(
const
uint8_t
*
key
);
int
receive_and_process_zap_reply
();
...
...
src/mechanism.hpp
View file @
498dc379
...
...
@@ -40,11 +40,11 @@ namespace zmq
virtual
~
mechanism_t
();
// Prepare next handshake
message
that is to be sent to the peer.
virtual
int
next_handshake_
message
(
msg_t
*
msg_
)
=
0
;
// Prepare next handshake
command
that is to be sent to the peer.
virtual
int
next_handshake_
command
(
msg_t
*
msg_
)
=
0
;
// Process the handshake
message
received from the peer.
virtual
int
process_handshake_
message
(
msg_t
*
msg_
)
=
0
;
// Process the handshake
command
received from the peer.
virtual
int
process_handshake_
command
(
msg_t
*
msg_
)
=
0
;
virtual
int
encode
(
msg_t
*
msg_
)
{
return
0
;
}
...
...
src/msg.hpp
View file @
498dc379
...
...
@@ -47,7 +47,8 @@ namespace zmq
// Message flags.
enum
{
more
=
1
,
more
=
1
,
// Followed by more parts
command
=
2
,
// Command frame (see ZMTP spec)
identity
=
64
,
shared
=
128
};
...
...
src/null_mechanism.cpp
View file @
498dc379
...
...
@@ -53,7 +53,7 @@ zmq::null_mechanism_t::~null_mechanism_t ()
{
}
int
zmq
::
null_mechanism_t
::
next_handshake_
message
(
msg_t
*
msg_
)
int
zmq
::
null_mechanism_t
::
next_handshake_
command
(
msg_t
*
msg_
)
{
if
(
ready_command_sent
)
{
errno
=
EAGAIN
;
...
...
@@ -78,7 +78,7 @@ int zmq::null_mechanism_t::next_handshake_message (msg_t *msg_)
unsigned
char
*
ptr
=
command_buffer
;
// Add mechanism string
memcpy
(
ptr
,
"
READY
\0
"
,
6
);
memcpy
(
ptr
,
"
\5
READY
"
,
6
);
ptr
+=
6
;
// Add socket type property
...
...
@@ -104,7 +104,7 @@ int zmq::null_mechanism_t::next_handshake_message (msg_t *msg_)
return
0
;
}
int
zmq
::
null_mechanism_t
::
process_handshake_
message
(
msg_t
*
msg_
)
int
zmq
::
null_mechanism_t
::
process_handshake_
command
(
msg_t
*
msg_
)
{
if
(
ready_command_received
)
{
errno
=
EPROTO
;
...
...
@@ -115,7 +115,7 @@ int zmq::null_mechanism_t::process_handshake_message (msg_t *msg_)
static_cast
<
unsigned
char
*>
(
msg_
->
data
());
size_t
bytes_left
=
msg_
->
size
();
if
(
bytes_left
<
6
||
memcmp
(
ptr
,
"
READY
\0
"
,
6
))
{
if
(
bytes_left
<
6
||
memcmp
(
ptr
,
"
\5
READY
"
,
6
))
{
errno
=
EPROTO
;
return
-
1
;
}
...
...
src/null_mechanism.hpp
View file @
498dc379
...
...
@@ -39,8 +39,8 @@ namespace zmq
virtual
~
null_mechanism_t
();
// mechanism implementation
virtual
int
next_handshake_
message
(
msg_t
*
msg_
);
virtual
int
process_handshake_
message
(
msg_t
*
msg_
);
virtual
int
next_handshake_
command
(
msg_t
*
msg_
);
virtual
int
process_handshake_
command
(
msg_t
*
msg_
);
virtual
int
zap_msg_available
();
virtual
bool
is_handshake_complete
()
const
;
...
...
src/plain_mechanism.cpp
View file @
498dc379
...
...
@@ -46,28 +46,28 @@ zmq::plain_mechanism_t::~plain_mechanism_t ()
{
}
int
zmq
::
plain_mechanism_t
::
next_handshake_
message
(
msg_t
*
msg_
)
int
zmq
::
plain_mechanism_t
::
next_handshake_
command
(
msg_t
*
msg_
)
{
int
rc
=
0
;
switch
(
state
)
{
case
sending_hello
:
rc
=
hello_command
(
msg_
);
rc
=
produce_hello
(
msg_
);
if
(
rc
==
0
)
state
=
waiting_for_welcome
;
break
;
case
sending_welcome
:
rc
=
welcome_command
(
msg_
);
rc
=
produce_welcome
(
msg_
);
if
(
rc
==
0
)
state
=
waiting_for_initiate
;
break
;
case
sending_initiate
:
rc
=
initiate_command
(
msg_
);
rc
=
produce_initiate
(
msg_
);
if
(
rc
==
0
)
state
=
waiting_for_ready
;
break
;
case
sending_ready
:
rc
=
ready_command
(
msg_
);
rc
=
produce_ready
(
msg_
);
if
(
rc
==
0
)
state
=
ready
;
break
;
...
...
@@ -78,28 +78,28 @@ int zmq::plain_mechanism_t::next_handshake_message (msg_t *msg_)
return
rc
;
}
int
zmq
::
plain_mechanism_t
::
process_handshake_
message
(
msg_t
*
msg_
)
int
zmq
::
plain_mechanism_t
::
process_handshake_
command
(
msg_t
*
msg_
)
{
int
rc
=
0
;
switch
(
state
)
{
case
waiting_for_hello
:
rc
=
process_hello
_command
(
msg_
);
rc
=
process_hello
(
msg_
);
if
(
rc
==
0
)
state
=
expecting_zap_reply
?
waiting_for_zap_reply
:
sending_welcome
;
break
;
case
waiting_for_welcome
:
rc
=
process_welcome
_command
(
msg_
);
rc
=
process_welcome
(
msg_
);
if
(
rc
==
0
)
state
=
sending_initiate
;
break
;
case
waiting_for_initiate
:
rc
=
process_initiate
_command
(
msg_
);
rc
=
process_initiate
(
msg_
);
if
(
rc
==
0
)
state
=
sending_ready
;
break
;
case
waiting_for_ready
:
rc
=
process_ready
_command
(
msg_
);
rc
=
process_ready
(
msg_
);
if
(
rc
==
0
)
state
=
ready
;
break
;
...
...
@@ -134,7 +134,7 @@ int zmq::plain_mechanism_t::zap_msg_available ()
return
rc
;
}
int
zmq
::
plain_mechanism_t
::
hello_command
(
msg_t
*
msg_
)
const
int
zmq
::
plain_mechanism_t
::
produce_hello
(
msg_t
*
msg_
)
const
{
const
std
::
string
username
=
options
.
plain_username
;
zmq_assert
(
username
.
length
()
<
256
);
...
...
@@ -142,15 +142,15 @@ int zmq::plain_mechanism_t::hello_command (msg_t *msg_) const
const
std
::
string
password
=
options
.
plain_password
;
zmq_assert
(
password
.
length
()
<
256
);
const
size_t
command_size
=
8
+
1
+
username
.
length
()
const
size_t
command_size
=
6
+
1
+
username
.
length
()
+
1
+
password
.
length
();
const
int
rc
=
msg_
->
init_size
(
command_size
);
errno_assert
(
rc
==
0
);
unsigned
char
*
ptr
=
static_cast
<
unsigned
char
*>
(
msg_
->
data
());
memcpy
(
ptr
,
"
HELLO "
,
8
);
ptr
+=
8
;
memcpy
(
ptr
,
"
\x05
HELLO"
,
6
);
ptr
+=
6
;
*
ptr
++
=
static_cast
<
unsigned
char
>
(
username
.
length
());
memcpy
(
ptr
,
username
.
c_str
(),
username
.
length
());
...
...
@@ -164,17 +164,17 @@ int zmq::plain_mechanism_t::hello_command (msg_t *msg_) const
}
int
zmq
::
plain_mechanism_t
::
process_hello
_command
(
msg_t
*
msg_
)
int
zmq
::
plain_mechanism_t
::
process_hello
(
msg_t
*
msg_
)
{
const
unsigned
char
*
ptr
=
static_cast
<
unsigned
char
*>
(
msg_
->
data
());
size_t
bytes_left
=
msg_
->
size
();
if
(
bytes_left
<
8
||
memcmp
(
ptr
,
"HELLO "
,
8
))
{
if
(
bytes_left
<
6
||
memcmp
(
ptr
,
"
\x05
HELLO"
,
6
))
{
errno
=
EPROTO
;
return
-
1
;
}
ptr
+=
8
;
bytes_left
-=
8
;
ptr
+=
6
;
bytes_left
-=
6
;
if
(
bytes_left
<
1
)
{
errno
=
EPROTO
;
...
...
@@ -226,27 +226,27 @@ int zmq::plain_mechanism_t::process_hello_command (msg_t *msg_)
return
0
;
}
int
zmq
::
plain_mechanism_t
::
welcome_command
(
msg_t
*
msg_
)
const
int
zmq
::
plain_mechanism_t
::
produce_welcome
(
msg_t
*
msg_
)
const
{
const
int
rc
=
msg_
->
init_size
(
8
);
errno_assert
(
rc
==
0
);
memcpy
(
msg_
->
data
(),
"
WELCOME
"
,
8
);
memcpy
(
msg_
->
data
(),
"
\x07
WELCOME
"
,
8
);
return
0
;
}
int
zmq
::
plain_mechanism_t
::
process_welcome
_command
(
msg_t
*
msg_
)
int
zmq
::
plain_mechanism_t
::
process_welcome
(
msg_t
*
msg_
)
{
const
unsigned
char
*
ptr
=
static_cast
<
unsigned
char
*>
(
msg_
->
data
());
size_t
bytes_left
=
msg_
->
size
();
if
(
bytes_left
!=
8
||
memcmp
(
ptr
,
"
WELCOME
"
,
8
))
{
if
(
bytes_left
!=
8
||
memcmp
(
ptr
,
"
\x07
WELCOME
"
,
8
))
{
errno
=
EPROTO
;
return
-
1
;
}
return
0
;
}
int
zmq
::
plain_mechanism_t
::
initiate_command
(
msg_t
*
msg_
)
const
int
zmq
::
plain_mechanism_t
::
produce_initiate
(
msg_t
*
msg_
)
const
{
unsigned
char
*
const
command_buffer
=
(
unsigned
char
*
)
malloc
(
512
);
alloc_assert
(
command_buffer
);
...
...
@@ -254,8 +254,8 @@ int zmq::plain_mechanism_t::initiate_command (msg_t *msg_) const
unsigned
char
*
ptr
=
command_buffer
;
// Add mechanism string
memcpy
(
ptr
,
"
INITIATE"
,
8
);
ptr
+=
8
;
memcpy
(
ptr
,
"
\x08
INITIATE"
,
9
);
ptr
+=
9
;
// Add socket type property
const
char
*
socket_type
=
socket_type_string
(
options
.
type
);
...
...
@@ -278,19 +278,21 @@ int zmq::plain_mechanism_t::initiate_command (msg_t *msg_) const
return
0
;
}
int
zmq
::
plain_mechanism_t
::
process_initiate
_command
(
msg_t
*
msg_
)
int
zmq
::
plain_mechanism_t
::
process_initiate
(
msg_t
*
msg_
)
{
const
unsigned
char
*
ptr
=
static_cast
<
unsigned
char
*>
(
msg_
->
data
());
size_t
bytes_left
=
msg_
->
size
();
if
(
bytes_left
<
8
||
memcmp
(
ptr
,
"INITIATE"
,
8
))
{
if
(
bytes_left
<
9
||
memcmp
(
ptr
,
"
\x08
INITIATE"
,
9
))
{
errno
=
EPROTO
;
return
-
1
;
}
return
parse_metadata
(
ptr
+
8
,
bytes_left
-
8
);
ptr
+=
9
;
bytes_left
-=
9
;
return
parse_metadata
(
ptr
,
bytes_left
);
}
int
zmq
::
plain_mechanism_t
::
ready_command
(
msg_t
*
msg_
)
const
int
zmq
::
plain_mechanism_t
::
produce_ready
(
msg_t
*
msg_
)
const
{
unsigned
char
*
const
command_buffer
=
(
unsigned
char
*
)
malloc
(
512
);
alloc_assert
(
command_buffer
);
...
...
@@ -298,7 +300,7 @@ int zmq::plain_mechanism_t::ready_command (msg_t *msg_) const
unsigned
char
*
ptr
=
command_buffer
;
// Add command name
memcpy
(
ptr
,
"
READY
\0
"
,
6
);
memcpy
(
ptr
,
"
\x05
READY
"
,
6
);
ptr
+=
6
;
// Add socket type property
...
...
@@ -322,12 +324,12 @@ int zmq::plain_mechanism_t::ready_command (msg_t *msg_) const
return
0
;
}
int
zmq
::
plain_mechanism_t
::
process_ready
_command
(
msg_t
*
msg_
)
int
zmq
::
plain_mechanism_t
::
process_ready
(
msg_t
*
msg_
)
{
const
unsigned
char
*
ptr
=
static_cast
<
unsigned
char
*>
(
msg_
->
data
());
size_t
bytes_left
=
msg_
->
size
();
if
(
bytes_left
<
6
||
memcmp
(
ptr
,
"
READY
\0
"
,
6
))
{
if
(
bytes_left
<
6
||
memcmp
(
ptr
,
"
\x05
READY
"
,
6
))
{
errno
=
EPROTO
;
return
-
1
;
}
...
...
src/plain_mechanism.hpp
View file @
498dc379
...
...
@@ -39,8 +39,8 @@ namespace zmq
virtual
~
plain_mechanism_t
();
// mechanism implementation
virtual
int
next_handshake_
message
(
msg_t
*
msg_
);
virtual
int
process_handshake_
message
(
msg_t
*
msg_
);
virtual
int
next_handshake_
command
(
msg_t
*
msg_
);
virtual
int
process_handshake_
command
(
msg_t
*
msg_
);
virtual
int
zap_msg_available
();
virtual
bool
is_handshake_complete
()
const
;
...
...
@@ -68,15 +68,15 @@ namespace zmq
state_t
state
;
int
hello_command
(
msg_t
*
msg_
)
const
;
int
welcome_command
(
msg_t
*
msg_
)
const
;
int
initiate_command
(
msg_t
*
msg_
)
const
;
int
ready_command
(
msg_t
*
msg_
)
const
;
int
produce_hello
(
msg_t
*
msg_
)
const
;
int
produce_welcome
(
msg_t
*
msg_
)
const
;
int
produce_initiate
(
msg_t
*
msg_
)
const
;
int
produce_ready
(
msg_t
*
msg_
)
const
;
int
process_hello
_command
(
msg_t
*
msg_
);
int
process_welcome
_command
(
msg_t
*
msg
);
int
process_ready
_command
(
msg_t
*
msg_
);
int
process_initiate
_command
(
msg_t
*
msg_
);
int
process_hello
(
msg_t
*
msg_
);
int
process_welcome
(
msg_t
*
msg
);
int
process_ready
(
msg_t
*
msg_
);
int
process_initiate
(
msg_t
*
msg_
);
void
send_zap_request
(
const
std
::
string
&
username
,
const
std
::
string
&
password
);
...
...
src/stream_engine.cpp
View file @
498dc379
...
...
@@ -395,7 +395,6 @@ bool zmq::stream_engine_t::handshake ()
{
zmq_assert
(
handshaking
);
zmq_assert
(
greeting_bytes_read
<
greeting_size
);
// Receive the greeting.
while
(
greeting_bytes_read
<
greeting_size
)
{
const
int
n
=
read
(
greeting_recv
+
greeting_bytes_read
,
...
...
@@ -492,8 +491,8 @@ bool zmq::stream_engine_t::handshake ()
insize
=
greeting_bytes_read
;
// To allow for interoperability with peers that do not forward
// their subscriptions, we inject a ph
ony subscription
// message into the incom
m
ing message stream.
// their subscriptions, we inject a ph
antom subscription message
// message into the incoming message stream.
if
(
options
.
type
==
ZMQ_PUB
||
options
.
type
==
ZMQ_XPUB
)
subscription_required
=
true
;
}
...
...
@@ -550,9 +549,8 @@ bool zmq::stream_engine_t::handshake ()
error
();
return
false
;
}
read_msg
=
&
stream_engine_t
::
next_handshake_message
;
write_msg
=
&
stream_engine_t
::
process_handshake_message
;
read_msg
=
&
stream_engine_t
::
next_handshake_command
;
write_msg
=
&
stream_engine_t
::
process_handshake_command
;
}
// Start polling for output if necessary.
...
...
@@ -598,12 +596,13 @@ int zmq::stream_engine_t::write_identity (msg_t *msg_)
return
0
;
}
int
zmq
::
stream_engine_t
::
next_handshake_
message
(
msg_t
*
msg_
)
int
zmq
::
stream_engine_t
::
next_handshake_
command
(
msg_t
*
msg_
)
{
zmq_assert
(
mechanism
!=
NULL
);
const
int
rc
=
mechanism
->
next_handshake_
message
(
msg_
);
const
int
rc
=
mechanism
->
next_handshake_
command
(
msg_
);
if
(
rc
==
0
)
{
msg_
->
set_flags
(
msg_t
::
command
);
if
(
mechanism
->
is_handshake_complete
())
mechanism_ready
();
}
...
...
@@ -611,11 +610,10 @@ int zmq::stream_engine_t::next_handshake_message (msg_t *msg_)
return
rc
;
}
int
zmq
::
stream_engine_t
::
process_handshake_
message
(
msg_t
*
msg_
)
int
zmq
::
stream_engine_t
::
process_handshake_
command
(
msg_t
*
msg_
)
{
zmq_assert
(
mechanism
!=
NULL
);
const
int
rc
=
mechanism
->
process_handshake_message
(
msg_
);
const
int
rc
=
mechanism
->
process_handshake_command
(
msg_
);
if
(
rc
==
0
)
{
if
(
mechanism
->
is_handshake_complete
())
mechanism_ready
();
...
...
src/stream_engine.hpp
View file @
498dc379
...
...
@@ -96,8 +96,8 @@ namespace zmq
int
read_identity
(
msg_t
*
msg_
);
int
write_identity
(
msg_t
*
msg_
);
int
next_handshake_
message
(
msg_t
*
msg
);
int
process_handshake_
message
(
msg_t
*
msg
);
int
next_handshake_
command
(
msg_t
*
msg
);
int
process_handshake_
command
(
msg_t
*
msg
);
int
pull_msg_from_session
(
msg_t
*
msg_
);
int
push_msg_to_session
(
msg_t
*
msg
);
...
...
@@ -171,8 +171,8 @@ namespace zmq
bool
io_error
;
// Indicates whether the engine is to inject a ph
ony
// subscription message into the incom
m
ing stream.
// Indicates whether the engine is to inject a ph
antom
// subscription message into the incoming stream.
// Needed to support old peers.
bool
subscription_required
;
...
...
src/v2_decoder.cpp
View file @
498dc379
...
...
@@ -54,6 +54,8 @@ int zmq::v2_decoder_t::flags_ready ()
msg_flags
=
0
;
if
(
tmpbuf
[
0
]
&
v2_protocol_t
::
more_flag
)
msg_flags
|=
msg_t
::
more
;
if
(
tmpbuf
[
0
]
&
v2_protocol_t
::
command_flag
)
msg_flags
|=
msg_t
::
command
;
// The payload length is either one or eight bytes,
// depending on whether the 'large' bit is set.
...
...
src/v2_encoder.cpp
View file @
498dc379
...
...
@@ -42,6 +42,8 @@ void zmq::v2_encoder_t::message_ready ()
protocol_flags
|=
v2_protocol_t
::
more_flag
;
if
(
in_progress
->
size
()
>
255
)
protocol_flags
|=
v2_protocol_t
::
large_flag
;
if
(
in_progress
->
flags
()
&
msg_t
::
command
)
protocol_flags
|=
v2_protocol_t
::
command_flag
;
// Encode the message length. For messages less then 256 bytes,
// the length is encoded as 8-bit unsigned integer. For larger
...
...
src/v2_protocol.hpp
View file @
498dc379
...
...
@@ -30,7 +30,8 @@ namespace zmq
enum
{
more_flag
=
1
,
large_flag
=
2
large_flag
=
2
,
command_flag
=
4
};
};
}
...
...
tests/Makefile.am
View file @
498dc379
...
...
@@ -3,7 +3,8 @@ INCLUDES = -I$(top_builddir)/include \
LDADD
=
$(top_builddir)
/src/libzmq.la
noinst_PROGRAMS
=
test_pair_inproc
\
noinst_PROGRAMS
=
test_system
\
test_pair_inproc
\
test_pair_tcp
\
test_reqrep_inproc
\
test_reqrep_tcp
\
...
...
@@ -44,6 +45,7 @@ noinst_PROGRAMS += test_shutdown_stress \
test_fork
endif
test_system_SOURCES
=
test_system.cpp
test_pair_inproc_SOURCES
=
test_pair_inproc.cpp testutil.hpp
test_pair_tcp_SOURCES
=
test_pair_tcp.cpp testutil.hpp
test_reqrep_inproc_SOURCES
=
test_reqrep_inproc.cpp testutil.hpp
...
...
@@ -84,10 +86,6 @@ test_timeo_SOURCES = test_timeo.cpp
test_fork_SOURCES
=
test_fork.cpp
endif
# Deprecated test cases
noinst_PROGRAMS
+=
test_raw_sock
test_raw_sock_SOURCES
=
test_raw_sock.cpp
# Run the test cases
TESTS
=
$(noinst_PROGRAMS)
XFAIL_TESTS
=
test_linger
tests/test_raw_sock.cpp
deleted
100644 → 0
View file @
1f037109
/*
Copyright (c) 2007-2013 Contributors as noted in the AUTHORS file
This file is part of 0MQ.
0MQ is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
0MQ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "../include/zmq.h"
#include <string.h>
#include "testutil.hpp"
// ZMTP protocol greeting structure
typedef
unsigned
char
byte
;
typedef
struct
{
byte
signature
[
10
];
// 0xFF 8*0x00 0x7F
byte
version
[
2
];
// 0x03 0x00 for ZMTP/3.0
byte
mechanism
[
20
];
// "NULL"
byte
as_server
;
byte
filler
[
31
];
}
zmtp_greeting_t
;
#define ZMTP_DEALER 5 // Socket type constants
#define ZMTP_ROUTER 6
// This is a greeting matching what 0MQ will send us; note the
// 8-byte size is set to 1 for backwards compatibility
static
zmtp_greeting_t
greeting
=
{
{
0xFF
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
1
,
0x7F
},
{
3
,
0
},
{
'N'
,
'U'
,
'L'
,
'L'
}
};
int
main
(
void
)
{
setup_test_environment
();
int
rc
;
// Set up our context and sockets
void
*
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
// We'll be using this socket in raw mode
void
*
router
=
zmq_socket
(
ctx
,
ZMQ_ROUTER
);
assert
(
router
);
int
on
=
1
;
rc
=
zmq_setsockopt
(
router
,
ZMQ_ROUTER_RAW
,
&
on
,
sizeof
(
on
));
assert
(
rc
==
0
);
int
zero
=
0
;
rc
=
zmq_setsockopt
(
router
,
ZMQ_LINGER
,
&
zero
,
sizeof
(
zero
));
assert
(
rc
==
0
);
rc
=
zmq_bind
(
router
,
"tcp://*:5555"
);
assert
(
rc
==
0
);
// We'll be using this socket as the other peer
void
*
dealer
=
zmq_socket
(
ctx
,
ZMQ_DEALER
);
assert
(
dealer
);
rc
=
zmq_setsockopt
(
dealer
,
ZMQ_LINGER
,
&
zero
,
sizeof
(
zero
));
assert
(
rc
==
0
);
rc
=
zmq_connect
(
dealer
,
"tcp://localhost:5555"
);
// Send a message on the dealer socket
rc
=
zmq_send
(
dealer
,
"Hello"
,
5
,
0
);
assert
(
rc
==
5
);
// First frame is identity
zmq_msg_t
identity
;
rc
=
zmq_msg_init
(
&
identity
);
assert
(
rc
==
0
);
rc
=
zmq_msg_recv
(
&
identity
,
router
,
0
);
assert
(
rc
>
0
);
assert
(
zmq_msg_more
(
&
identity
));
// Second frame is greeting signature
byte
buffer
[
255
];
rc
=
zmq_recv
(
router
,
buffer
,
255
,
0
);
assert
(
rc
==
10
);
assert
(
memcmp
(
buffer
,
greeting
.
signature
,
10
)
==
0
);
// Send our own protocol greeting
rc
=
zmq_msg_send
(
&
identity
,
router
,
ZMQ_SNDMORE
);
assert
(
rc
>
0
);
rc
=
zmq_send
(
router
,
&
greeting
,
sizeof
(
greeting
),
0
);
assert
(
rc
==
sizeof
(
greeting
));
// Now we expect the data from the DEALER socket
// First frame is, again, the identity of the connection
rc
=
zmq_msg_recv
(
&
identity
,
router
,
0
);
assert
(
rc
>
0
);
assert
(
zmq_msg_more
(
&
identity
));
// Second frame contains the rest of greeting along with
// the Ready command
rc
=
zmq_recv
(
router
,
buffer
,
255
,
0
);
assert
(
rc
==
97
);
// First two bytes are major and minor version numbers.
assert
(
buffer
[
0
]
==
3
);
// ZMTP/3.0
assert
(
buffer
[
1
]
==
0
);
// Mechanism is "NULL"
assert
(
memcmp
(
buffer
+
2
,
"NULL
\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
"
,
22
)
==
0
);
assert
(
memcmp
(
buffer
+
54
,
"
\0\51
READY
\0
"
,
8
)
==
0
);
assert
(
memcmp
(
buffer
+
62
,
"
\13
Socket-Type
\0\0\0\6
DEALER"
,
22
)
==
0
);
assert
(
memcmp
(
buffer
+
84
,
"
\10
Identity
\0\0\0\0
"
,
13
)
==
0
);
// Announce we are ready
memcpy
(
buffer
,
"
\0\51
READY
\0
"
,
8
);
memcpy
(
buffer
+
8
,
"
\13
Socket-Type
\0\0\0\6
ROUTER"
,
22
);
memcpy
(
buffer
+
30
,
"
\10
Identity
\0\0\0\0
"
,
13
);
// Send Ready command
rc
=
zmq_msg_send
(
&
identity
,
router
,
ZMQ_SNDMORE
);
assert
(
rc
>
0
);
rc
=
zmq_send
(
router
,
buffer
,
43
,
0
);
assert
(
rc
==
43
);
// Now we expect the data from the DEALER socket
// First frame is, again, the identity of the connection
rc
=
zmq_msg_recv
(
&
identity
,
router
,
0
);
assert
(
rc
>
0
);
assert
(
zmq_msg_more
(
&
identity
));
// Third frame contains Hello message from DEALER
rc
=
zmq_recv
(
router
,
buffer
,
sizeof
buffer
,
0
);
assert
(
rc
==
7
);
// Then we have a 5-byte message "Hello"
assert
(
buffer
[
0
]
==
0
);
// Flags = 0
assert
(
buffer
[
1
]
==
5
);
// Size = 5
assert
(
memcmp
(
buffer
+
2
,
"Hello"
,
5
)
==
0
);
// Send "World" back to DEALER
rc
=
zmq_msg_send
(
&
identity
,
router
,
ZMQ_SNDMORE
);
assert
(
rc
>
0
);
byte
world
[]
=
{
0
,
5
,
'W'
,
'o'
,
'r'
,
'l'
,
'd'
};
rc
=
zmq_send
(
router
,
world
,
sizeof
(
world
),
0
);
assert
(
rc
==
sizeof
(
world
));
// Expect response on DEALER socket
rc
=
zmq_recv
(
dealer
,
buffer
,
255
,
0
);
assert
(
rc
==
5
);
assert
(
memcmp
(
buffer
,
"World"
,
5
)
==
0
);
rc
=
zmq_close
(
dealer
);
assert
(
rc
==
0
);
rc
=
zmq_close
(
router
);
assert
(
rc
==
0
);
rc
=
zmq_ctx_term
(
ctx
);
assert
(
rc
==
0
);
return
0
;
}
tests/test_security_curve.cpp
View file @
498dc379
...
...
@@ -17,12 +17,12 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "platform.hpp"
#include <string.h>
#include <stdlib.h>
#include "testutil.hpp"
#include "../include/zmq_utils.h"
#include "../src/z85_codec.hpp"
#include "../src/platform.hpp"
// Test keys from the zmq_curve man page
static
char
client_public
[]
=
"Yne@$w-vo<fVvi]a<NY6T1ed:M$fCG*[IaLV{hID"
;
...
...
@@ -53,7 +53,7 @@ static void zap_handler (void *ctx)
int
size
=
zmq_recv
(
zap
,
client_key
,
32
,
0
);
assert
(
size
==
32
);
char
client_key_text
[
4
0
];
char
client_key_text
[
4
1
];
Z85_encode
(
client_key_text
,
client_key
,
32
);
assert
(
streq
(
version
,
"1.0"
));
...
...
tests/test_stream.cpp
View file @
498dc379
...
...
@@ -38,7 +38,7 @@ typedef struct {
// 8-byte size is set to 1 for backwards compatibility
static
zmtp_greeting_t
greeting
=
{
{
0xFF
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
1
,
0x7F
},
{
3
,
0
},
{
'N'
,
'U'
,
'L'
,
'L'
}
};
=
{
{
0xFF
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
1
,
0x7F
},
{
3
,
0
},
{
'N'
,
'U'
,
'L'
,
'L'
}
};
static
void
test_stream_to_dealer
(
void
)
...
...
@@ -98,7 +98,12 @@ test_stream_to_dealer (void)
// Second frame contains the rest of greeting along with
// the Ready command
rc
=
zmq_recv
(
stream
,
buffer
,
255
,
0
);
int
bytes_read
=
0
;
while
(
bytes_read
<
97
)
{
rc
=
zmq_recv
(
stream
,
buffer
+
bytes_read
,
255
-
bytes_read
,
0
);
assert
(
rc
>=
0
);
bytes_read
+=
rc
;
}
assert
(
rc
==
97
);
// First two bytes are major and minor version numbers.
...
...
@@ -106,13 +111,13 @@ test_stream_to_dealer (void)
assert
(
buffer
[
1
]
==
0
);
// Mechanism is "NULL"
assert
(
memcmp
(
buffer
+
2
,
"NULL
\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
"
,
2
2
)
==
0
);
assert
(
memcmp
(
buffer
+
54
,
"
\
0\51
READY
\0
"
,
8
)
==
0
);
assert
(
memcmp
(
buffer
+
2
,
"NULL
\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
"
,
2
0
)
==
0
);
assert
(
memcmp
(
buffer
+
54
,
"
\
4\51\5
READY
"
,
8
)
==
0
);
assert
(
memcmp
(
buffer
+
62
,
"
\13
Socket-Type
\0\0\0\6
DEALER"
,
22
)
==
0
);
assert
(
memcmp
(
buffer
+
84
,
"
\10
Identity
\0\0\0\0
"
,
13
)
==
0
);
// Announce we are ready
memcpy
(
buffer
,
"
\
0\51
READY
\0
"
,
8
);
memcpy
(
buffer
,
"
\
4\51\5
READY
"
,
8
);
memcpy
(
buffer
+
8
,
"
\13
Socket-Type
\0\0\0\6
ROUTER"
,
22
);
memcpy
(
buffer
+
30
,
"
\10
Identity
\0\0\0\0
"
,
13
);
...
...
tests/test_system.cpp
0 → 100644
View file @
498dc379
/*
Copyright (c) 2007-2013 Contributors as noted in the AUTHORS file
This file is part of 0MQ.
0MQ is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
0MQ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "../include/zmq.h"
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <assert.h>
// This test case stresses the system to shake out known configuration
// problems. We're not using libzmq here but direct system calls. Note
// that code may need wrapping to be properly portable.
int
main
(
void
)
{
// Check that we can create 1,000 sockets
int
handle
[
1000
];
int
count
;
for
(
count
=
0
;
count
<
1000
;
count
++
)
{
handle
[
count
]
=
socket
(
AF_INET
,
SOCK_STREAM
,
IPPROTO_TCP
);
if
(
handle
[
count
]
==
-
1
)
{
printf
(
"W: Only able to create %d sockets on this box
\n
"
,
count
);
printf
(
"I: Tune your system to increase maximum allowed file handles
\n
"
);
#if defined (ZMQ_HAVE_OSX)
printf
(
"I: On OS/X, run 'ulimit -n 1200' in bash"
);
#elseif defined (ZMQ_HAVE_LINUX)
printf
(
"I: On Linux, run 'ulimit -n 1200' in bash"
);
#endif
return
-
1
;
}
}
// Release the socket handles
while
(
count
)
close
(
handle
[
count
--
]);
}
tools/curve_keygen.c
View file @
498dc379
...
...
@@ -56,7 +56,7 @@ int main (void)
int
rc
=
crypto_box_keypair
(
public_key
,
secret_key
);
assert
(
rc
==
0
);
char
encoded
[
4
0
];
char
encoded
[
4
1
];
Z85_encode
(
encoded
,
public_key
,
32
);
puts
(
"
\n
== CURVE PUBLIC KEY =="
);
puts
(
encoded
);
...
...
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