• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef NETDUTILS_SOCKETOPTION_H
18 #define NETDUTILS_SOCKETOPTION_H
19 
20 #include <netinet/in.h>
21 #include <sys/socket.h>
22 #include <string>
23 
24 #include "netdutils/Fd.h"
25 #include "netdutils/Status.h"
26 
27 namespace android {
28 namespace netdutils {
29 
30 // Turn on simple "boolean" socket options.
31 //
32 // This is simple wrapper for options that are enabled via code of the form:
33 //
34 //     int on = 1;
35 //     setsockopt(..., &on, sizeof(on));
36 Status enableSockopt(Fd sock, int level, int optname);
37 
38 // Turn on TCP keepalives, and set keepalive parameters for this socket.
39 //
40 // A parameter value of zero does not set that parameter.
41 //
42 // Typical system defaults are:
43 //
44 //     idleTime (in seconds)
45 //     $ cat /proc/sys/net/ipv4/tcp_keepalive_time
46 //     7200
47 //
48 //     numProbes
49 //     $ cat /proc/sys/net/ipv4/tcp_keepalive_probes
50 //     9
51 //
52 //     probeInterval (in seconds)
53 //     $ cat /proc/sys/net/ipv4/tcp_keepalive_intvl
54 //     75
55 Status enableTcpKeepAlives(Fd sock, unsigned idleTime, unsigned numProbes, unsigned probeInterval);
56 
57 }  // namespace netdutils
58 }  // namespace android
59 
60 #endif /* NETDUTILS_SOCKETOPTION_H */
61