Merge "Add utils connect, setsockopt, bind, sendTo"
This commit is contained in:
@@ -3476,11 +3476,15 @@ package android.net.util {
|
||||
method public static void attachControlPacketFilter(java.io.FileDescriptor, int) throws java.net.SocketException;
|
||||
method public static void attachDhcpFilter(java.io.FileDescriptor) throws java.net.SocketException;
|
||||
method public static void attachRaFilter(java.io.FileDescriptor, int) throws java.net.SocketException;
|
||||
method public static void bindSocket(java.io.FileDescriptor, java.net.SocketAddress) throws android.system.ErrnoException, java.net.SocketException;
|
||||
method public static void bindSocketToInterface(java.io.FileDescriptor, String) throws android.system.ErrnoException;
|
||||
method public static void closeSocket(java.io.FileDescriptor) throws java.io.IOException;
|
||||
method public static void connectSocket(java.io.FileDescriptor, java.net.SocketAddress) throws android.system.ErrnoException, java.net.SocketException;
|
||||
method public static java.net.SocketAddress makeNetlinkSocketAddress(int, int);
|
||||
method public static java.net.SocketAddress makePacketSocketAddress(short, int);
|
||||
method public static java.net.SocketAddress makePacketSocketAddress(int, byte[]);
|
||||
method public static void sendTo(java.io.FileDescriptor, byte[], int, int, int, java.net.SocketAddress) throws android.system.ErrnoException, java.net.SocketException;
|
||||
method public static void setSocketTimeValueOption(java.io.FileDescriptor, int, int, long) throws android.system.ErrnoException;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -912,11 +912,15 @@ package android.net.util {
|
||||
method public static void attachControlPacketFilter(java.io.FileDescriptor, int) throws java.net.SocketException;
|
||||
method public static void attachDhcpFilter(java.io.FileDescriptor) throws java.net.SocketException;
|
||||
method public static void attachRaFilter(java.io.FileDescriptor, int) throws java.net.SocketException;
|
||||
method public static void bindSocket(java.io.FileDescriptor, java.net.SocketAddress) throws android.system.ErrnoException, java.net.SocketException;
|
||||
method public static void bindSocketToInterface(java.io.FileDescriptor, String) throws android.system.ErrnoException;
|
||||
method public static void closeSocket(java.io.FileDescriptor) throws java.io.IOException;
|
||||
method public static void connectSocket(java.io.FileDescriptor, java.net.SocketAddress) throws android.system.ErrnoException, java.net.SocketException;
|
||||
method public static java.net.SocketAddress makeNetlinkSocketAddress(int, int);
|
||||
method public static java.net.SocketAddress makePacketSocketAddress(short, int);
|
||||
method public static java.net.SocketAddress makePacketSocketAddress(int, byte[]);
|
||||
method public static void sendTo(java.io.FileDescriptor, byte[], int, int, int, java.net.SocketAddress) throws android.system.ErrnoException, java.net.SocketException;
|
||||
method public static void setSocketTimeValueOption(java.io.FileDescriptor, int, int, long) throws android.system.ErrnoException;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user