summaryrefslogtreecommitdiff
path: root/chromium/net/socket/tcp_socket.cc
blob: ad5250620d0f1b1eb09c6c100c5d67f4babc4a6d (plain)
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
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "net/socket/tcp_socket.h"

#include "build/build_config.h"

#if defined(OS_POSIX)
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#elif defined(OS_WIN)
#include <winsock2.h>
#endif

namespace net {

bool SetTCPNoDelay(SocketDescriptor socket, bool no_delay) {
#if defined(OS_POSIX)
  int on = no_delay ? 1 : 0;
#elif defined(OS_WIN)
  BOOL on = no_delay ? TRUE : FALSE;
#endif
  return setsockopt(socket, IPPROTO_TCP, TCP_NODELAY,
                    reinterpret_cast<const char*>(&on), sizeof(on)) == 0;
}

}  // namespace net