forked from netty/netty
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added SCTP Codec Handlers + minor refactoring
- Loading branch information
Showing
12 changed files
with
243 additions
and
149 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
codec/src/main/java/io/netty/handler/codec/sctp/SctpMessageDecoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2012 The Netty Project | ||
* | ||
* The Netty Project licenses this file to you under the Apache License, | ||
* version 2.0 (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package io.netty.handler.codec.sctp; | ||
|
||
import com.sun.nio.sctp.MessageInfo; | ||
import io.netty.buffer.ByteBuf; | ||
import io.netty.buffer.Unpooled; | ||
import io.netty.channel.ChannelHandlerContext; | ||
import io.netty.channel.socket.SctpMessage; | ||
import io.netty.handler.codec.MessageToMessageDecoder; | ||
|
||
public class SctpMessageDecoder extends MessageToMessageDecoder<SctpMessage, ByteBuf> { | ||
private ByteBuf cumulation = Unpooled.EMPTY_BUFFER; | ||
|
||
@Override | ||
public ByteBuf decode(ChannelHandlerContext ctx, SctpMessage msg) throws Exception { | ||
ByteBuf byteBuf = cumulation = Unpooled.wrappedBuffer(cumulation, msg.getPayloadBuffer()); | ||
if (msg.isComplete()) { | ||
cumulation = Unpooled.EMPTY_BUFFER; | ||
return byteBuf; | ||
} else { | ||
return null; | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
codec/src/main/java/io/netty/handler/codec/sctp/SctpMessageEncoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright 2012 The Netty Project | ||
* | ||
* The Netty Project licenses this file to you under the Apache License, | ||
* version 2.0 (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package io.netty.handler.codec.sctp; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import io.netty.buffer.MessageBuf; | ||
import io.netty.buffer.Unpooled; | ||
import io.netty.channel.ChannelFuture; | ||
import io.netty.channel.ChannelHandlerContext; | ||
import io.netty.channel.ChannelOutboundMessageHandlerAdapter; | ||
import io.netty.channel.socket.SctpMessage; | ||
import io.netty.handler.codec.EncoderException; | ||
|
||
public class SctpMessageEncoder extends ChannelOutboundMessageHandlerAdapter<ByteBuf> { | ||
private final int streamIdentifier; | ||
private final int protocolIdentifier; | ||
|
||
public SctpMessageEncoder(int streamIdentifier, int protocolIdentifier) { | ||
this.streamIdentifier = streamIdentifier; | ||
this.protocolIdentifier = protocolIdentifier; | ||
} | ||
|
||
@Override | ||
public void flush(ChannelHandlerContext ctx, ChannelFuture future) throws Exception { | ||
ByteBuf in = ctx.outboundByteBuffer(); | ||
|
||
try { | ||
MessageBuf<Object> out = ctx.nextOutboundMessageBuffer(); | ||
ByteBuf payload = Unpooled.buffer(in.readableBytes()); | ||
payload.writeBytes(in); | ||
out.add(new SctpMessage(streamIdentifier, protocolIdentifier, payload)); | ||
in.discardReadBytes(); | ||
} catch (Throwable t) { | ||
ctx.fireExceptionCaught(new EncoderException(t)); | ||
} | ||
|
||
ctx.flush(future); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
codec/src/main/java/io/netty/handler/codec/sctp/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright 2012 The Netty Project | ||
* | ||
* The Netty Project licenses this file to you under the Apache License, | ||
* version 2.0 (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
/** | ||
* Encoder and decoder which transform a {@link io.netty.channel.socket.SctpMessage} into a | ||
* {@link io.netty.buffer.ByteBuf} and vice versa. | ||
* | ||
* @apiviz.exclude \.oneone\. | ||
*/ | ||
package io.netty.handler.codec.sctp; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 0 additions & 120 deletions
120
transport/src/main/java/io/netty/channel/socket/SctpData.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.