本文整理汇总了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();
}
示例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();//最后一个使用方要释放引用
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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;
}
示例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;
}