📄 trnonblockingserverprocessor.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: TRNonBlockingServerProcessor.java
package org.gudy.azureus2.core3.tracker.server.impl.tcp.nonblocking;
import java.io.*;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import org.gudy.azureus2.core3.tracker.server.impl.TRTrackerServerImpl;
import org.gudy.azureus2.core3.tracker.server.impl.tcp.TRTrackerServerProcessorTCP;
import org.gudy.azureus2.core3.tracker.server.impl.tcp.TRTrackerServerTCP;
import org.gudy.azureus2.core3.util.*;
// Referenced classes of package org.gudy.azureus2.core3.tracker.server.impl.tcp.nonblocking:
// TRNonBlockingServer
public abstract class TRNonBlockingServerProcessor extends TRTrackerServerProcessorTCP
{
private static final int READ_BUFFER_INITIAL = 1024;
private static final int READ_BUFFER_INCREMENT = 1024;
private static final int READ_BUFFER_LIMIT = 32768;
private SocketChannel socket_channel;
private long start_time;
private ByteBuffer read_buffer;
private String request_header;
private ByteBuffer write_buffer;
protected TRNonBlockingServerProcessor(TRTrackerServerTCP _server, SocketChannel _socket)
{
super(_server);
socket_channel = _socket;
start_time = SystemTime.getCurrentTime();
read_buffer = ByteBuffer.allocate(1024);
}
protected int processRead()
{
byte data[];
if (read_buffer.remaining() == 0)
{
int capacity = read_buffer.capacity();
if (capacity == 32768)
return -1;
read_buffer.position(0);
data = new byte[capacity];
read_buffer.get(data);
read_buffer = ByteBuffer.allocate(capacity + 1024);
read_buffer.put(data);
}
int len = socket_channel.read(read_buffer);
if (len < 0)
return -1;
if (len == 0)
return 2;
int i;
data = read_buffer.array();
i = read_buffer.position() - 4;
_L1:
if (i < 0)
break MISSING_BLOCK_LABEL_189;
if (data[i] != 13 || data[i + 1] != 10 || data[i + 2] != 13 || data[i + 3] != 10)
break MISSING_BLOCK_LABEL_183;
request_header = new String(data, 0, read_buffer.position());
getServer().runProcessor(this);
return 0;
i--;
goto _L1
return 1;
IOException e;
e;
return -1;
}
protected int processWrite()
{
if (write_buffer == null)
return -1;
if (!write_buffer.hasRemaining())
return 0;
int written = socket_channel.write(write_buffer);
if (written == 0)
return 2;
if (write_buffer.hasRemaining())
return 1;
return 0;
IOException e;
e;
return -1;
}
public void runSupport()
{
boolean async = false;
String url;
final AESemaphore went_async[];
final ByteArrayOutputStream async_stream[];
AsyncController async_control;
url = request_header.substring(4).trim();
int pos = url.indexOf(" ");
url = url.substring(0, pos);
went_async = (new AESemaphore[] {
null
});
async_stream = (new ByteArrayOutputStream[] {
null
});
async_control = new AsyncController() {
final AESemaphore val$went_async[];
final ByteArrayOutputStream val$async_stream[];
final TRNonBlockingServerProcessor this$0;
public void setAsyncStart()
{
went_async[0] = new AESemaphore("async");
}
public void setAsyncComplete()
{
went_async[0].reserve();
asyncProcessComplete(async_stream[0]);
}
{
this$0 = TRNonBlockingServerProcessor.this;
went_async = aaesemaphore;
async_stream = abytearrayoutputstream;
super();
}
};
ByteArrayOutputStream response = process(request_header, request_header.toLowerCase(), url, (InetSocketAddress)socket_channel.socket().getRemoteSocketAddress(), TRTrackerServerImpl.restrict_non_blocking_requests, new ByteArrayInputStream(new byte[0]), async_control);
if (response == null)
async = true;
else
if (went_async[0] != null)
{
async_stream[0] = response;
async = true;
} else
{
write_buffer = ByteBuffer.wrap(response.toByteArray());
}
if (went_async[0] != null)
went_async[0].release();
break MISSING_BLOCK_LABEL_184;
Exception exception;
exception;
if (went_async[0] != null)
went_async[0].release();
throw exception;
if (!async)
((TRNonBlockingServer)getServer()).readyToWrite(this);
break MISSING_BLOCK_LABEL_241;
Throwable e;
e;
if (!async)
((TRNonBlockingServer)getServer()).readyToWrite(this);
break MISSING_BLOCK_LABEL_241;
Exception exception1;
exception1;
if (!async)
((TRNonBlockingServer)getServer()).readyToWrite(this);
throw exception1;
}
protected abstract ByteArrayOutputStream process(String s, String s1, String s2, InetSocketAddress inetsocketaddress, boolean flag, InputStream inputstream, AsyncController asynccontroller)
throws IOException;
protected void asyncProcessComplete(ByteArrayOutputStream response)
{
write_buffer = ByteBuffer.wrap(response.toByteArray());
((TRNonBlockingServer)getServer()).readyToWrite(this);
}
protected SocketChannel getSocketChannel()
{
return socket_channel;
}
protected long getStartTime()
{
return start_time;
}
public void interruptTask()
{
}
protected void failed()
{
}
protected void completed()
{
}
protected void closed()
{
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -