java.net.Socket

    1. public synchronized int getReceiveBufferSize() throws SocketException{
    2. if (isClosed())
    3. throw new SocketException("Socket is closed");
    4. int result = 0;
    5. Object o = getImpl().getOption(SocketOptions.SO_RCVBUF);
    6. if (o instanceof Integer) {
    7. result = ((Integer)o).intValue();
    8. }
    9. return result;
    10. }
    11. public synchronized void setReceiveBufferSize(int size)
    12. throws SocketException{
    13. if (size <= 0) {
    14. throw new IllegalArgumentException("invalid receive size");
    15. }
    16. if (isClosed())
    17. throw new SocketException("Socket is closed");
    18. getImpl().setOption(SocketOptions.SO_RCVBUF, new Integer(size));
    19. }
    20. public synchronized int getSendBufferSize() throws SocketException {
    21. if (isClosed())
    22. throw new SocketException("Socket is closed");
    23. int result = 0;
    24. Object o = getImpl().getOption(SocketOptions.SO_SNDBUF);
    25. if (o instanceof Integer) {
    26. result = ((Integer)o).intValue();
    27. }
    28. return result;
    29. }
    30. public synchronized void setSendBufferSize(int size)
    31. throws SocketException{
    32. if (!(size > 0)) {
    33. throw new IllegalArgumentException("negative send size");
    34. }
    35. if (isClosed())
    36. throw new SocketException("Socket is closed");
    37. getImpl().setOption(SocketOptions.SO_SNDBUF, new Integer(size));
    38. }
    39. //java.net.SocketOptions
    40. @Native public final static int SO_RCVBUF = 0x1002;
    41. @Native public final static int SO_SNDBUF = 0x1001;

    Socket ReceiveBufferSize SendBufferSize - 图1