wsky / top-push

Message-push abstraction component, provide useful messaging components.
8 stars 4 forks source link

does jetty-websocket support subprotocol efficiently #5

Open wsky opened 11 years ago

wsky commented 11 years ago

http://stackoverflow.com/questions/11797708/jetty-websocket-custom-events

"jetty-websocket没有为子协议解析提供好的注入架构,对于pushserver而言效率和定制性问题 如binarymessage完整接收后返回对应拷贝,上层无法对这个buffer copy过程和子协议解析做精确控制,造成内存碎片等问题"

is it right?

public void onMessage(String arg0) {}

There is no need to discuss textmessage.

how about binary message?

public void onMessage(byte[] data, int offset, int length) {}

http://grepcode.com/file/repo1.maven.org/maven2/org.eclipse.jetty/jetty-websocket/8.1.7.v20120910/org/eclipse/jetty/websocket/WebSocketConnectionRFC6455.java#444

public void sendMessage(byte[] content, int offset, int length) throws IOException
        {
           if (_closedOut)
                throw new IOException("closedOut "+_closeCode+":"+_closeMessage);
            _outbound.addFrame((byte)FLAG_FIN,WebSocketConnectionRFC6455.OP_BINARY,content,offset,length);
            checkWriteable();
       }

the question is "byte[] data" is temporary or buffered.

http://grepcode.com/file/repo1.maven.org/maven2/org.eclipse.jetty/jetty-websocket/8.1.7.v20120910/org/eclipse/jetty/websocket/WebSocketGeneratorRFC6455.java?av=f#158

if (mask)
                {
                    for (int i=0;i<chunk;i++)
                        _buffer.put((byte)(content[offset+ (payload-remaining)+i]^_mask[+_m++%4]));
                }
                else
                    _buffer.put(content, offset + (payload - remaining), chunk);

byte[] always provided with offset and length, it's buffered in jetty, so, you also need care about you buffer self

once copy for send: your-buffer -> jetty-buffer

once copy for receive: jetty-buffer -> your-buffer

wsky commented 11 years ago

usually, binary message is more suitable for push-server