我算是死的瞑目了,找了这么久的源码终于找答案了,结果到了最后竟然跟我来一个native的方法
先查到这个类
- abstract class AbstractPlainDatagramSocketImpl extends DatagramSocketImpl
复制代码 在看到这个类中的方法receive0
- protected synchronized void receive(DatagramPacket p)
- throws IOException {
- receive0(p);
- }
复制代码 操,有时一个抽象的方法
- protected abstract void receive0(DatagramPacket p)
- throws IOException;
复制代码
接着继续,查到这个类
- class DualStackPlainDatagramSocketImpl extends AbstractPlainDatagramSocketImpl
复制代码 在这个类中又要查socketReceiveOrPeekData方法
- protected synchronized void receive0(DatagramPacket p) throws IOException {
- int nativefd = checkAndReturnNativeFD();
- if (p == null)
- throw new NullPointerException("packet");
- if (p.getData() == null)
- throw new NullPointerException("packet buffer");
- socketReceiveOrPeekData(nativefd, p, timeout, connected, false /*receive*/);
- }
复制代码
结果一看,竟然是一个nativ方法- private static native int socketReceiveOrPeekData(int fd, DatagramPacket packet,
- int timeout, boolean connected, boolean peek) throws IOException;
复制代码
让我郁闷至死,至死都没弄明白是receive方法是怎么接收send方法发送的数据包
|