当前位置: 首页>>代码示例>>Java>>正文


Java DatagramPacket.release方法代码示例

本文整理汇总了Java中io.netty.channel.socket.DatagramPacket.release方法的典型用法代码示例。如果您正苦于以下问题:Java DatagramPacket.release方法的具体用法?Java DatagramPacket.release怎么用?Java DatagramPacket.release使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.netty.channel.socket.DatagramPacket的用法示例。


在下文中一共展示了DatagramPacket.release方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: release

import io.netty.channel.socket.DatagramPacket; //导入方法依赖的package包/类
/**
 * 释放所有内存
 */
private void release()
{
  for (DatagramPacket dp : this.inputs)
  {
    dp.release();
  }
  this.inputs.clear();
  for (KcpOnUdp ku : this.kcps.values())
  {
    if (!ku.isClosed())
    {
      ku.release();
    }
  }
  this.kcps.clear();
}
 
开发者ID:beykery,项目名称:jkcp,代码行数:20,代码来源:KcpThread.java

示例2: channelRead

import io.netty.channel.socket.DatagramPacket; //导入方法依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    DatagramPacket datagramPacket = (DatagramPacket) msg;
    Packet packet = PacketDecoder.decodeFrame(datagramPacket);
    receiver.onReceive(packet, connection);
    datagramPacket.release();//最后一个使用方要释放引用
}
 
开发者ID:mpusher,项目名称:mpush,代码行数:8,代码来源:UDPChannelHandler.java

示例3: onReceive

import io.netty.channel.socket.DatagramPacket; //导入方法依赖的package包/类
/**
 * receive DatagramPacket
 *
 * @param dp
 */
private void onReceive(DatagramPacket dp)
{
  if (this.running)
  {
    InetSocketAddress sender = dp.sender();
    int hash = sender.hashCode();
    hash = hash < 0 ? -hash : hash;
    this.workers[hash % workers.length].input(dp);
  } else
  {
    dp.release();
  }
}
 
开发者ID:beykery,项目名称:jkcp,代码行数:19,代码来源:KcpServer.java

示例4: onReceive

import io.netty.channel.socket.DatagramPacket; //导入方法依赖的package包/类
/**
 * 收到服务器消息
 *
 * @param dp
 */
private void onReceive(DatagramPacket dp)
{
    if (this.kcp != null && this.running)
    {
        this.kcp.input(dp.content());
        synchronized (this.waitLock)
        {
            this.waitLock.notify();
        }
    } else
    {
        dp.release();
    }
}
 
开发者ID:beykery,项目名称:jkcp,代码行数:20,代码来源:KcpClient.java

示例5: input

import io.netty.channel.socket.DatagramPacket; //导入方法依赖的package包/类
/**
 * 收到输入
 */
void input(DatagramPacket dp)
{
  if (this.running)
  {
    this.inputs.add(dp);
    synchronized (this.lock)
    {
      lock.notify();
    }
  } else
  {
    dp.release();
  }
}
 
开发者ID:beykery,项目名称:jkcp,代码行数:18,代码来源:KcpThread.java

示例6: channelRead0

import io.netty.channel.socket.DatagramPacket; //导入方法依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket packet) throws Exception {
  packet.retain();
  final boolean succeeded = queue.offer(packet);
  if (succeeded) {
    gaugeMap.put(GAUGE_NUM_QUEUED_PACKETS, queuedPacketCount.incrementAndGet());
    gaugeMap.put(GAUGE_PACKET_QUEUE_SIZE, queue.size());
  } else {
    gaugeMap.put(GAUGE_NUM_DROPPED_PACKETS, droppedPacketCount.incrementAndGet());
    // allow Netty to collect the buffer
    packet.release();
  }
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:14,代码来源:PacketQueueUDPHandler.java

示例7: receivePacket

import io.netty.channel.socket.DatagramPacket; //导入方法依赖的package包/类
private boolean receivePacket() throws Exception {
    DatagramPacket datagramPacket = this.socket.readPacket();
    if (datagramPacket != null) {
        // Check this early
        try {
            String source = datagramPacket.sender().getHostString();
            currentSource = source; //in order to block address
            if (this.block.containsKey(source)) {
                return true;
            }

            if (this.ipSec.containsKey(source)) {
                this.ipSec.put(source, this.ipSec.get(source) + 1);
            } else {
                this.ipSec.put(source, 1);
            }

            ByteBuf byteBuf = datagramPacket.content();
            if (byteBuf.readableBytes() == 0) {
                // Exit early to process another packet
                return true;
            }
            byte[] buffer = new byte[byteBuf.readableBytes()];
            byteBuf.readBytes(buffer);
            int len = buffer.length;
            int port = datagramPacket.sender().getPort();

            this.receiveBytes += len;

            byte pid = buffer[0];

            if (pid == UNCONNECTED_PONG.ID) {
                return false;
            }

            Packet packet = this.getPacketFromPool(pid);
            if (packet != null) {
                packet.buffer = buffer;
                this.getSession(source, port).handlePacket(packet);
                return true;
            } else if (pid == UNCONNECTED_PING.ID) {
                packet = new UNCONNECTED_PING();
                packet.buffer = buffer;
                packet.decode();

                UNCONNECTED_PONG pk = new UNCONNECTED_PONG();
                pk.serverID = this.getID();
                pk.pingID = ((UNCONNECTED_PING) packet).pingID;
                pk.serverName = this.getName();
                this.sendPacket(pk, source, port);
            } else if (buffer.length != 0) {
                this.streamRAW(source, port, buffer);
                return true;
            } else {
                return false;
            }
        } finally {
            datagramPacket.release();
        }
    }

    return false;
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:64,代码来源:SessionManager.java

示例8: receivePacket

import io.netty.channel.socket.DatagramPacket; //导入方法依赖的package包/类
private boolean receivePacket() throws Exception {
    DatagramPacket datagramPacket = this.socket.readPacket();
    if (datagramPacket != null) {
        // Check this early
        String source = datagramPacket.sender().getHostString();
        currentSource = source; //in order to block address
        if (this.block.containsKey(source)) {
            datagramPacket.release();
            return true;
        }

        if (this.ipSec.containsKey(source)) {
            this.ipSec.put(source, this.ipSec.get(source) + 1);
        } else {
            this.ipSec.put(source, 1);
        }

        ByteBuf byteBuf = datagramPacket.content();
        byte[] buffer = new byte[byteBuf.readableBytes()];
        byteBuf.readBytes(buffer);
        datagramPacket.release();
        int len = buffer.length;
        int port = datagramPacket.sender().getPort();
        if (len > 0) {
            this.receiveBytes += len;

            byte pid = buffer[0];

            if (pid == UNCONNECTED_PONG.ID) {
                return false;
            }

            Packet packet = this.getPacketFromPool(pid);
            if (packet != null) {
                packet.buffer = buffer;
                this.getSession(source, port).handlePacket(packet);
                return true;
            } else if (pid == UNCONNECTED_PING.ID) {
                packet = new UNCONNECTED_PING();
                packet.buffer = buffer;
                packet.decode();

                UNCONNECTED_PONG pk = new UNCONNECTED_PONG();
                pk.serverID = this.getID();
                pk.pingID = ((UNCONNECTED_PING) packet).pingID;
                pk.serverName = this.getName();
                this.sendPacket(pk, source, port);
            } else if (buffer.length != 0) {
                this.streamRAW(source, port, buffer);
                return true;
            } else {
                return false;
            }
        } else {
            return true;
        }
    }

    return false;
}
 
开发者ID:BukkitPE,项目名称:BukkitPE,代码行数:61,代码来源:SessionManager.java


注:本文中的io.netty.channel.socket.DatagramPacket.release方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。