1 /* 2 * Copyright (C) 2011 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 package android.system; 18 19 import static android.annotation.SystemApi.Client.MODULE_LIBRARIES; 20 21 import android.annotation.SystemApi; 22 23 import libcore.util.Objects; 24 25 /** 26 * Corresponds to C's {@code struct linger} from 27 * <a href="http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html"><sys/socket.h></a> 28 * 29 * When enabled, a {@link Os.close(java.io.FileDescriptor) or 30 * {@link Os.shutdown(java.io.FileDescriptor, int)} will 31 * not return until all queued messages for the socket have been successfully sent or the 32 * linger timeout has been reached. Otherwise, the call returns immediately and the closing is 33 * done in the background. 34 * 35 * See <a href="https://man7.org/linux/man-pages/man7/socket.7.html">socket(7)</a> 36 * for linger struct description. 37 * 38 * @see Os#getsockoptLinger(java.io.FileDescriptor, int, int). 39 * @see OsConstants#SO_LINGER 40 * 41 * @hide 42 */ 43 @SystemApi(client = MODULE_LIBRARIES) 44 @libcore.api.CorePlatformApi(status = libcore.api.CorePlatformApi.Status.STABLE) 45 public final class StructLinger { 46 /** 47 * Whether or not linger is enabled. Non-zero is on. 48 * 49 * @hide 50 */ 51 public final int l_onoff; 52 53 /** 54 * Linger time in seconds. 55 * 56 * @hide 57 */ 58 @SystemApi(client = MODULE_LIBRARIES) 59 @libcore.api.CorePlatformApi(status = libcore.api.CorePlatformApi.Status.STABLE) 60 public final int l_linger; 61 62 /** 63 * Constructs linger structure. 64 * 65 * @param l_onoff whether or not linger is enabled, non-zero is on 66 * @param l_linger linger time, in seconds 67 * 68 * @hide 69 */ 70 @SystemApi(client = MODULE_LIBRARIES) 71 @libcore.api.CorePlatformApi(status = libcore.api.CorePlatformApi.Status.STABLE) StructLinger(int l_onoff, int l_linger)72 public StructLinger(int l_onoff, int l_linger) { 73 this.l_onoff = l_onoff; 74 this.l_linger = l_linger; 75 } 76 77 /** 78 * Returns whether linger is on or not. 79 * 80 * @return {@code true} if linger is enabled, and {@code false} otherwise 81 * 82 * @hide 83 */ 84 @SystemApi(client = MODULE_LIBRARIES) 85 @libcore.api.CorePlatformApi(status = libcore.api.CorePlatformApi.Status.STABLE) isOn()86 public boolean isOn() { 87 return l_onoff != 0; 88 } 89 90 /** 91 * @hide 92 */ 93 @Override toString()94 public String toString() { 95 return Objects.toString(this); 96 } 97 } 98