| 262 | } |
| 263 | |
| 264 | void |
| 265 | Connection::apply_options(NetVCOptions const &opt) |
| 266 | { |
| 267 | // Set options which can be changed after a connection is established |
| 268 | // ignore other changes |
| 269 | if (SOCK_STREAM == sock_type) { |
| 270 | if (opt.sockopt_flags & NetVCOptions::SOCK_OPT_NO_DELAY) { |
| 271 | sock.enable_option(IPPROTO_TCP, TCP_NODELAY); |
| 272 | Dbg(dbg_ctl_socket, "::open: setsockopt() TCP_NODELAY on socket"); |
| 273 | } |
| 274 | if (opt.sockopt_flags & NetVCOptions::SOCK_OPT_KEEP_ALIVE) { |
| 275 | sock.enable_option(SOL_SOCKET, SO_KEEPALIVE); |
| 276 | Dbg(dbg_ctl_socket, "::open: setsockopt() SO_KEEPALIVE on socket"); |
| 277 | } |
| 278 | if (opt.sockopt_flags & NetVCOptions::SOCK_OPT_LINGER_ON) { |
| 279 | struct linger l; |
| 280 | l.l_onoff = 1; |
| 281 | l.l_linger = 0; |
| 282 | safe_setsockopt(sock.get_fd(), SOL_SOCKET, SO_LINGER, reinterpret_cast<char *>(&l), sizeof(l)); |
| 283 | Dbg(dbg_ctl_socket, "::open:: setsockopt() turn on SO_LINGER on socket"); |
| 284 | } |
| 285 | #ifdef TCP_NOTSENT_LOWAT |
| 286 | if (opt.sockopt_flags & NetVCOptions::SOCK_OPT_TCP_NOTSENT_LOWAT) { |
| 287 | uint32_t lowat = opt.packet_notsent_lowat; |
| 288 | safe_setsockopt(sock.get_fd(), IPPROTO_TCP, TCP_NOTSENT_LOWAT, reinterpret_cast<char *>(&lowat), sizeof(lowat)); |
| 289 | Dbg(dbg_ctl_socket, "::open:: setsockopt() set TCP_NOTSENT_LOWAT to %d", lowat); |
| 290 | } |
| 291 | #endif |
| 292 | } |
| 293 | |
| 294 | #if TS_HAS_SO_MARK |
| 295 | if (opt.sockopt_flags & NetVCOptions::SOCK_OPT_PACKET_MARK) { |
| 296 | uint32_t mark = opt.packet_mark; |
| 297 | safe_setsockopt(sock.get_fd(), SOL_SOCKET, SO_MARK, reinterpret_cast<char *>(&mark), sizeof(uint32_t)); |
| 298 | } |
| 299 | #endif |
| 300 | |
| 301 | #if TS_HAS_IP_TOS |
| 302 | if (opt.sockopt_flags & NetVCOptions::SOCK_OPT_PACKET_TOS) { |
| 303 | uint32_t tos = opt.packet_tos; |
| 304 | if (addr.isIp4()) { |
| 305 | safe_setsockopt(sock.get_fd(), IPPROTO_IP, IP_TOS, reinterpret_cast<char *>(&tos), sizeof(uint32_t)); |
| 306 | } else if (addr.isIp6()) { |
| 307 | safe_setsockopt(sock.get_fd(), IPPROTO_IPV6, IPV6_TCLASS, reinterpret_cast<char *>(&tos), sizeof(uint32_t)); |
| 308 | } |
| 309 | } |
| 310 | #endif |
| 311 | } |
no test coverage detected