Merge "Add utils connect, setsockopt, bind, sendTo"

am: 1e002eede3

Change-Id: Ida2a99f35affe3cb9213f71ba622ace51c4d6f57
This commit is contained in:
Remi NGUYEN VAN
2019-01-29 03:21:22 -08:00
committed by android-build-merger
3 changed files with 41 additions and 0 deletions

View File

@@ -27,6 +27,7 @@ import android.system.ErrnoException;
import android.system.NetlinkSocketAddress;
import android.system.Os;
import android.system.PacketSocketAddress;
import android.system.StructTimeval;
import libcore.io.IoBridge;
@@ -78,6 +79,38 @@ public class SocketUtils {
return new PacketSocketAddress(ifIndex, hwAddr);
}
/**
* Set an option on a socket that takes a time value argument.
*/
public static void setSocketTimeValueOption(
FileDescriptor fd, int level, int option, long millis) throws ErrnoException {
Os.setsockoptTimeval(fd, level, option, StructTimeval.fromMillis(millis));
}
/**
* Bind a socket to the specified address.
*/
public static void bindSocket(FileDescriptor fd, SocketAddress addr)
throws ErrnoException, SocketException {
Os.bind(fd, addr);
}
/**
* Connect a socket to the specified address.
*/
public static void connectSocket(FileDescriptor fd, SocketAddress addr)
throws ErrnoException, SocketException {
Os.connect(fd, addr);
}
/**
* Send a message on a socket, using the specified SocketAddress.
*/
public static void sendTo(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount,
int flags, SocketAddress addr) throws ErrnoException, SocketException {
Os.sendto(fd, bytes, byteOffset, byteCount, flags, addr);
}
/**
* @see IoBridge#closeAndSignalBlockedThreads(FileDescriptor)
*/