mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-12 10:33:52 +01:00
Problem: various warnings regarding SOCKET vs. int in test_security_curve
Solution: Use fd_t
This commit is contained in:
parent
28631d1cd3
commit
3ee65906af
@ -42,30 +42,6 @@ void tearDown ()
|
||||
teardown_test_context ();
|
||||
}
|
||||
|
||||
// duplicated from fd.hpp
|
||||
#ifdef ZMQ_HAVE_WINDOWS
|
||||
#define close closesocket
|
||||
#if defined _MSC_VER && _MSC_VER <= 1400
|
||||
typedef UINT_PTR fd_t;
|
||||
enum
|
||||
{
|
||||
retired_fd = (fd_t) (~0)
|
||||
};
|
||||
#else
|
||||
typedef SOCKET fd_t;
|
||||
enum
|
||||
{
|
||||
retired_fd = (fd_t) INVALID_SOCKET
|
||||
};
|
||||
#endif
|
||||
#else
|
||||
typedef int fd_t;
|
||||
enum
|
||||
{
|
||||
retired_fd = -1
|
||||
};
|
||||
#endif
|
||||
|
||||
fd_t get_fd (void *socket)
|
||||
{
|
||||
fd_t fd;
|
||||
|
@ -241,9 +241,9 @@ void test_curve_security_with_plain_client_credentials ()
|
||||
expect_zmtp_mechanism_mismatch (client, my_endpoint, server, server_mon);
|
||||
}
|
||||
|
||||
int connect_vanilla_socket (char *my_endpoint)
|
||||
fd_t connect_vanilla_socket (char *my_endpoint)
|
||||
{
|
||||
int s;
|
||||
fd_t s;
|
||||
struct sockaddr_in ip4addr;
|
||||
|
||||
unsigned short int port;
|
||||
@ -267,7 +267,7 @@ int connect_vanilla_socket (char *my_endpoint)
|
||||
void test_curve_security_unauthenticated_message ()
|
||||
{
|
||||
// Unauthenticated messages from a vanilla socket shouldn't be received
|
||||
int s = connect_vanilla_socket (my_endpoint);
|
||||
fd_t s = connect_vanilla_socket (my_endpoint);
|
||||
// send anonymous ZMTP/1.0 greeting
|
||||
send (s, "\x01\x00", 2, 0);
|
||||
// send sneaky message that shouldn't be received
|
||||
@ -279,7 +279,7 @@ void test_curve_security_unauthenticated_message ()
|
||||
close (s);
|
||||
}
|
||||
|
||||
void send_all (int fd, const char *data, size_t size)
|
||||
void send_all (fd_t fd, const char *data, socket_size_t size)
|
||||
{
|
||||
while (size > 0) {
|
||||
int res = send (fd, data, size, 0);
|
||||
@ -289,12 +289,12 @@ void send_all (int fd, const char *data, size_t size)
|
||||
}
|
||||
}
|
||||
|
||||
template <size_t N> void send (int fd, const char (&data)[N])
|
||||
template <size_t N> void send (fd_t fd, const char (&data)[N])
|
||||
{
|
||||
send_all (fd, data, N - 1);
|
||||
}
|
||||
|
||||
void send_greeting (int s)
|
||||
void send_greeting (fd_t s)
|
||||
{
|
||||
send (s, "\xff\0\0\0\0\0\0\0\0\x7f"); // signature
|
||||
send (s, "\x03\x00"); // version 3.0
|
||||
@ -305,7 +305,7 @@ void send_greeting (int s)
|
||||
|
||||
void test_curve_security_invalid_hello_wrong_length ()
|
||||
{
|
||||
int s = connect_vanilla_socket (my_endpoint);
|
||||
fd_t s = connect_vanilla_socket (my_endpoint);
|
||||
|
||||
// send GREETING
|
||||
send_greeting (s);
|
||||
@ -360,7 +360,7 @@ uint64_t htonll (uint64_t value)
|
||||
}
|
||||
#endif
|
||||
|
||||
template <size_t N> void send_command (int s, char (&command)[N])
|
||||
template <size_t N> void send_command (fd_t s, char (&command)[N])
|
||||
{
|
||||
if (N < 256) {
|
||||
send (s, "\x04");
|
||||
@ -376,7 +376,7 @@ template <size_t N> void send_command (int s, char (&command)[N])
|
||||
|
||||
void test_curve_security_invalid_hello_command_name ()
|
||||
{
|
||||
int s = connect_vanilla_socket (my_endpoint);
|
||||
fd_t s = connect_vanilla_socket (my_endpoint);
|
||||
|
||||
send_greeting (s);
|
||||
|
||||
@ -401,7 +401,7 @@ void test_curve_security_invalid_hello_command_name ()
|
||||
|
||||
void test_curve_security_invalid_hello_version ()
|
||||
{
|
||||
int s = connect_vanilla_socket (my_endpoint);
|
||||
fd_t s = connect_vanilla_socket (my_endpoint);
|
||||
|
||||
send_greeting (s);
|
||||
|
||||
@ -424,7 +424,7 @@ void test_curve_security_invalid_hello_version ()
|
||||
close (s);
|
||||
}
|
||||
|
||||
void flush_read (int fd)
|
||||
void flush_read (fd_t fd)
|
||||
{
|
||||
int res;
|
||||
char buf[256];
|
||||
@ -434,9 +434,9 @@ void flush_read (int fd)
|
||||
TEST_ASSERT_NOT_EQUAL (-1, res);
|
||||
}
|
||||
|
||||
void recv_all (int fd, uint8_t *data, size_t len)
|
||||
void recv_all (fd_t fd, uint8_t *data, socket_size_t len)
|
||||
{
|
||||
size_t received = 0;
|
||||
socket_size_t received = 0;
|
||||
while (received < len) {
|
||||
int res = recv (fd, (char *) data, len, 0);
|
||||
TEST_ASSERT_GREATER_THAN_INT (0, res);
|
||||
@ -446,17 +446,17 @@ void recv_all (int fd, uint8_t *data, size_t len)
|
||||
}
|
||||
}
|
||||
|
||||
void recv_greeting (int fd)
|
||||
void recv_greeting (fd_t fd)
|
||||
{
|
||||
uint8_t greeting[64];
|
||||
recv_all (fd, greeting, 64);
|
||||
// TODO assert anything about the greeting received from the server?
|
||||
}
|
||||
|
||||
int connect_exchange_greeting_and_send_hello (char *my_endpoint,
|
||||
zmq::curve_client_tools_t &tools)
|
||||
fd_t connect_exchange_greeting_and_send_hello (char *my_endpoint,
|
||||
zmq::curve_client_tools_t &tools)
|
||||
{
|
||||
int s = connect_vanilla_socket (my_endpoint);
|
||||
fd_t s = connect_vanilla_socket (my_endpoint);
|
||||
|
||||
send_greeting (s);
|
||||
recv_greeting (s);
|
||||
@ -474,7 +474,7 @@ void test_curve_security_invalid_initiate_wrong_length ()
|
||||
{
|
||||
zmq::curve_client_tools_t tools = make_curve_client_tools ();
|
||||
|
||||
int s = connect_exchange_greeting_and_send_hello (my_endpoint, tools);
|
||||
fd_t s = connect_exchange_greeting_and_send_hello (my_endpoint, tools);
|
||||
|
||||
// receive but ignore WELCOME
|
||||
flush_read (s);
|
||||
@ -497,13 +497,13 @@ void test_curve_security_invalid_initiate_wrong_length ()
|
||||
close (s);
|
||||
}
|
||||
|
||||
int connect_exchange_greeting_and_hello_welcome (
|
||||
fd_t connect_exchange_greeting_and_hello_welcome (
|
||||
char *my_endpoint,
|
||||
void *server_mon,
|
||||
int timeout,
|
||||
zmq::curve_client_tools_t &tools)
|
||||
{
|
||||
int s = connect_exchange_greeting_and_send_hello (my_endpoint, tools);
|
||||
fd_t s = connect_exchange_greeting_and_send_hello (my_endpoint, tools);
|
||||
|
||||
// receive but ignore WELCOME
|
||||
uint8_t welcome[welcome_length + 2];
|
||||
@ -524,7 +524,7 @@ int connect_exchange_greeting_and_hello_welcome (
|
||||
void test_curve_security_invalid_initiate_command_name ()
|
||||
{
|
||||
zmq::curve_client_tools_t tools = make_curve_client_tools ();
|
||||
int s = connect_exchange_greeting_and_hello_welcome (
|
||||
fd_t s = connect_exchange_greeting_and_hello_welcome (
|
||||
my_endpoint, server_mon, timeout, tools);
|
||||
|
||||
char initiate[257];
|
||||
@ -546,7 +546,7 @@ void test_curve_security_invalid_initiate_command_name ()
|
||||
void test_curve_security_invalid_initiate_command_encrypted_cookie ()
|
||||
{
|
||||
zmq::curve_client_tools_t tools = make_curve_client_tools ();
|
||||
int s = connect_exchange_greeting_and_hello_welcome (
|
||||
fd_t s = connect_exchange_greeting_and_hello_welcome (
|
||||
my_endpoint, server_mon, timeout, tools);
|
||||
|
||||
char initiate[257];
|
||||
@ -568,7 +568,7 @@ void test_curve_security_invalid_initiate_command_encrypted_cookie ()
|
||||
void test_curve_security_invalid_initiate_command_encrypted_content ()
|
||||
{
|
||||
zmq::curve_client_tools_t tools = make_curve_client_tools ();
|
||||
int s = connect_exchange_greeting_and_hello_welcome (
|
||||
fd_t s = connect_exchange_greeting_and_hello_welcome (
|
||||
my_endpoint, server_mon, timeout, tools);
|
||||
|
||||
char initiate[257];
|
||||
|
@ -88,6 +88,32 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// duplicated from fd.hpp
|
||||
#ifdef ZMQ_HAVE_WINDOWS
|
||||
#define close closesocket
|
||||
typedef int socket_size_t;
|
||||
#if defined _MSC_VER && _MSC_VER <= 1400
|
||||
typedef UINT_PTR fd_t;
|
||||
enum
|
||||
{
|
||||
retired_fd = (fd_t) (~0)
|
||||
};
|
||||
#else
|
||||
typedef SOCKET fd_t;
|
||||
enum
|
||||
{
|
||||
retired_fd = (fd_t) INVALID_SOCKET
|
||||
};
|
||||
#endif
|
||||
#else
|
||||
typedef size_t socket_size_t;
|
||||
typedef int fd_t;
|
||||
enum
|
||||
{
|
||||
retired_fd = -1
|
||||
};
|
||||
#endif
|
||||
|
||||
#define LIBZMQ_UNUSED(object) (void) object
|
||||
|
||||
// Bounce a message from client to server and back
|
||||
@ -351,11 +377,11 @@ int is_ipv6_available (void)
|
||||
test_addr.sin6_family = AF_INET6;
|
||||
inet_pton (AF_INET6, "::1", &(test_addr.sin6_addr));
|
||||
|
||||
#ifdef ZMQ_HAVE_WINDOWS
|
||||
SOCKET fd = socket (AF_INET6, SOCK_STREAM, IPPROTO_IP);
|
||||
if (fd == INVALID_SOCKET)
|
||||
fd_t fd = socket (AF_INET6, SOCK_STREAM, IPPROTO_IP);
|
||||
if (fd == retired_fd)
|
||||
ipv6 = 0;
|
||||
else {
|
||||
#ifdef ZMQ_HAVE_WINDOWS
|
||||
setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (const char *) &ipv6,
|
||||
sizeof (int));
|
||||
rc = setsockopt (fd, IPPROTO_IPV6, IPV6_V6ONLY, (const char *) &ipv6,
|
||||
@ -367,13 +393,7 @@ int is_ipv6_available (void)
|
||||
if (rc == SOCKET_ERROR)
|
||||
ipv6 = 0;
|
||||
}
|
||||
closesocket (fd);
|
||||
}
|
||||
#else
|
||||
int fd = socket (AF_INET6, SOCK_STREAM, IPPROTO_IP);
|
||||
if (fd == -1)
|
||||
ipv6 = 0;
|
||||
else {
|
||||
setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &ipv6, sizeof (int));
|
||||
rc = setsockopt (fd, IPPROTO_IPV6, IPV6_V6ONLY, &ipv6, sizeof (int));
|
||||
if (rc != 0)
|
||||
@ -383,9 +403,9 @@ int is_ipv6_available (void)
|
||||
if (rc != 0)
|
||||
ipv6 = 0;
|
||||
}
|
||||
#endif
|
||||
close (fd);
|
||||
}
|
||||
#endif
|
||||
|
||||
return ipv6;
|
||||
#endif // _WIN32_WINNT < 0x0600
|
||||
@ -442,13 +462,4 @@ int test_inet_pton (int af_, const char *src_, void *dst_)
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(ZMQ_HAVE_WINDOWS)
|
||||
|
||||
int close (int fd)
|
||||
{
|
||||
return closesocket (fd);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user