1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
| int zmq::tcp_listener_t::set_address (const char *protocol_, const char *addr_, int backlog_) { if (strcmp (protocol_, "tcp") == 0 ) {
int rc = resolve_ip_interface (&addr, &addr_len, addr_); if (rc != 0) return -1;
s = open_socket (addr.ss_family, SOCK_STREAM, IPPROTO_TCP); if (s == -1) return -1;
int flag = 1; rc = setsockopt (s, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof (int)); errno_assert (rc == 0);
flag = fcntl (s, F_GETFL, 0); if (flag == -1) flag = 0; rc = fcntl (s, F_SETFL, flag | O_NONBLOCK); errno_assert (rc != -1);
rc = bind (s, (struct sockaddr*) &addr, addr_len); if (rc != 0) { int err = errno; if (close () != 0) return -1; errno = err; return -1; }
rc = listen (s, backlog_); if (rc != 0) { int err = errno; if (close () != 0) return -1; errno = err; return -1; }
return 0; } else if (strcmp (protocol_, "ipc") == 0) {
::unlink (addr_);
int rc = resolve_local_path (&addr, &addr_len, addr_); if (rc != 0) return -1;
s = socket (AF_UNIX, SOCK_STREAM, 0); if (s == -1) return -1;
int flag = fcntl (s, F_GETFL, 0); if (flag == -1) flag = 0; rc = fcntl (s, F_SETFL, flag | O_NONBLOCK); errno_assert (rc != -1);
rc = bind (s, (struct sockaddr*) &addr, addr_len); if (rc != 0) { int err = errno; if (close () != 0) return -1; errno = err; return -1; } has_file = true;
rc = listen (s, backlog_); if (rc != 0) { int err = errno; if (close () != 0) return -1; errno = err; return -1; }
return 0; } else { errno = EPROTONOSUPPORT; return -1; } }
|