This commit is contained in:
Redkale
2018-04-28 21:36:46 +08:00
parent 18459b71c2
commit db99445878
2 changed files with 8 additions and 9 deletions

View File

@@ -12,6 +12,7 @@ import java.nio.channels.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicLong;
import org.redkale.util.AnyValue;
/**
* 协议底层Server
@@ -53,7 +54,7 @@ public abstract class ProtocolServer {
//最大连接数小于1表示无限制
protected int maxconns;
public abstract void open() throws IOException;
public abstract void open(AnyValue config) throws IOException;
public abstract void bind(SocketAddress local, int backlog) throws IOException;
@@ -111,7 +112,7 @@ public abstract class ProtocolServer {
}
@Override
public void open() throws IOException {
public void open(AnyValue config) throws IOException {
DatagramChannel ch = DatagramChannel.open();
ch.configureBlocking(true);
this.serverChannel = ch;
@@ -203,14 +204,9 @@ public abstract class ProtocolServer {
}
@Override
public void open() throws IOException {
public void open(AnyValue config) throws IOException {
group = AsynchronousChannelGroup.withCachedThreadPool(context.executor, 1);
this.serverChannel = AsynchronousServerSocketChannel.open(group);
try {
if (supportTcpNoDelay()) this.serverChannel.setOption(StandardSocketOptions.TCP_NODELAY, true);
if (supportTcpKeepAlive()) this.serverChannel.setOption(StandardSocketOptions.SO_KEEPALIVE, true);
} catch (IOException e) {
}
}
@Override

View File

@@ -225,10 +225,13 @@ public abstract class Server<K extends Serializable, C extends Context, R extend
this.context = this.createContext();
this.prepare.init(this.context, config);
this.serverChannel = ProtocolServer.create(this.protocol, context);
this.serverChannel.open();
this.serverChannel.open(config);
if (this.serverChannel.supportedOptions().contains(StandardSocketOptions.TCP_NODELAY)) {
this.serverChannel.setOption(StandardSocketOptions.TCP_NODELAY, true);
}
if (this.serverChannel.supportedOptions().contains(StandardSocketOptions.SO_KEEPALIVE)) {
this.serverChannel.setOption(StandardSocketOptions.SO_KEEPALIVE, true);
}
serverChannel.bind(address, backlog);
serverChannel.setMaxconns(this.maxconns);
serverChannel.accept();