11 #ifndef ZMQ_HAVE_WINDOWS
12 #include <sys/socket.h>
13 #include <netinet/in.h>
23 uint8_t num_methods_) :
24 num_methods (num_methods_)
26 for (uint8_t
i = 0;
i < num_methods_;
i++)
31 _bytes_encoded (0), _bytes_written (0)
40 *ptr++ =
static_cast<uint8_t
> (greeting_.
num_methods);
51 tcp_write (fd_, _buf + _bytes_written, _bytes_encoded - _bytes_written);
53 _bytes_written +=
static_cast<size_t> (rc);
59 return _bytes_written < _bytes_encoded;
64 _bytes_encoded = _bytes_written = 0;
78 const int rc =
tcp_read (fd_, _buf + _bytes_read, 2 - _bytes_read);
80 _bytes_read +=
static_cast<size_t> (rc);
89 return _bytes_read == 2;
106 username (username_), password (password_)
114 _bytes_encoded (0), _bytes_written (0)
121 unsigned char *ptr = _buf;
123 *ptr++ =
static_cast<unsigned char> (req_.
username.size ());
126 *ptr++ =
static_cast<unsigned char> (req_.
password.size ());
130 _bytes_encoded = ptr - _buf;
137 tcp_write (fd_, _buf + _bytes_written, _bytes_encoded - _bytes_written);
139 _bytes_written +=
static_cast<size_t> (rc);
145 return _bytes_written < _bytes_encoded;
150 _bytes_encoded = _bytes_written = 0;
155 response_code (response_code_)
167 const int rc =
tcp_read (fd_, _buf + _bytes_read, 2 - _bytes_read);
169 _bytes_read +=
static_cast<size_t> (rc);
178 return _bytes_read == 2;
202 _bytes_encoded (0), _bytes_written (0)
210 unsigned char *ptr = _buf;
215 #if defined ZMQ_HAVE_OPENVMS && defined __ia64 && __INITIAL_POINTER_SIZE == 64
216 __addrinfo64 hints, *res =
NULL;
218 addrinfo hints, *res =
NULL;
221 memset (&hints, 0,
sizeof hints);
224 hints.ai_flags = AI_NUMERICHOST;
226 const int rc = getaddrinfo (req_.
hostname.c_str (),
NULL, &hints, &res);
227 if (rc == 0 && res->ai_family == AF_INET) {
228 const struct sockaddr_in *sockaddr_in =
229 reinterpret_cast<const struct sockaddr_in *
> (res->ai_addr);
231 memcpy (ptr, &sockaddr_in->sin_addr, 4);
233 }
else if (rc == 0 && res->ai_family == AF_INET6) {
234 const struct sockaddr_in6 *sockaddr_in6 =
235 reinterpret_cast<const struct sockaddr_in6 *
> (res->ai_addr);
237 memcpy (ptr, &sockaddr_in6->sin6_addr, 16);
241 *ptr++ =
static_cast<unsigned char> (req_.
hostname.size ());
249 *ptr++ = req_.
port / 256;
250 *ptr++ = req_.
port % 256;
252 _bytes_encoded = ptr - _buf;
259 tcp_write (fd_, _buf + _bytes_written, _bytes_encoded - _bytes_written);
261 _bytes_written +=
static_cast<size_t> (rc);
267 return _bytes_written < _bytes_encoded;
272 _bytes_encoded = _bytes_written = 0;
278 response_code (response_code_),
address (address_), port (port_)
293 const uint8_t atyp = _buf[3];
294 zmq_assert (atyp == 0x01 || atyp == 0x03 || atyp == 0x04);
297 else if (atyp == 0x03)
299 else if (atyp == 0x04)
302 const int rc =
tcp_read (fd_, _buf + _bytes_read,
n);
304 _bytes_read +=
static_cast<size_t> (rc);
307 if (_bytes_read >= 2)
310 if (_bytes_read >= 3)
313 if (_bytes_read >= 4) {
314 const uint8_t atyp = _buf[3];
315 if (atyp != 0x01 && atyp != 0x03 && atyp != 0x04)
327 const uint8_t atyp = _buf[3];
328 zmq_assert (atyp == 0x01 || atyp == 0x03 || atyp == 0x04);
330 return _bytes_read == 10;
332 return _bytes_read > 4 && _bytes_read == 4 + 1 + _buf[4] + 2u;
334 return _bytes_read == 22;