mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-06-18 03:40:25 +08:00
add logicface: UdpTransport&StreamTransport
This commit is contained in:
@@ -9,6 +9,7 @@ import packet.LpPacket;
|
||||
import util.ByteHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.SocketException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.util.Collection;
|
||||
@@ -139,15 +140,41 @@ public class StreamTransport extends Transport implements ITransport{
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public LpPacket receive() {
|
||||
while (true){
|
||||
break;
|
||||
public LpPacket receive() throws LogicFaceException {
|
||||
try {
|
||||
while (true) {
|
||||
LpPacket lpPacket = this.receive();
|
||||
if (lpPacket != null) {
|
||||
return lpPacket;
|
||||
}
|
||||
int recvRet = this.channel.read(ByteBuffer.wrap(ByteHelper.
|
||||
getLenBytes(this.recvBuf, (int) this.recvLen, (int) (this.recvBuf.length - this.recvLen))));
|
||||
if(recvRet<0){
|
||||
return null;
|
||||
}
|
||||
this.recvLen+=recvRet;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new LogicFaceException("StreamTransport.receive: "+e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置读超时时间
|
||||
* @param duration 超时时间 , 以 毫秒 为单位, 小于等于0,表示永不超时
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean setReadTimeout(long duration) {
|
||||
return false;
|
||||
public boolean setReadTimeout(long duration) throws LogicFaceException {
|
||||
try {
|
||||
if (duration <= 0) {
|
||||
this.channel.socket().setSoTimeout(0);
|
||||
return true;
|
||||
}
|
||||
this.channel.socket().setSoTimeout((int)(duration));
|
||||
return false;
|
||||
} catch (SocketException e) {
|
||||
throw new LogicFaceException("StreamTransport.setReadTimeout"+e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user