Search in sources :

Example 6 with EzySocketStream

use of com.tvd12.ezyfoxserver.socket.EzySocketStream in project ezyfox-server by youngmonkeys.

the class EzyBlockingSocketStreamQueueTest method test.

@Test
public void test() {
    EzyBlockingSocketStreamQueue queue = new EzyBlockingSocketStreamQueue(2);
    EzySocketStream stream = mock(EzySocketStream.class);
    assert queue.isEmpty();
    assert queue.add(stream);
    assert !queue.isFull();
    assert !queue.isEmpty();
    assert queue.add(stream);
    assert queue.isFull();
    assert !queue.add(stream);
    queue.remove(stream);
    assert queue.size() == 1;
}
Also used : EzyBlockingSocketStreamQueue(com.tvd12.ezyfoxserver.socket.EzyBlockingSocketStreamQueue) EzySocketStream(com.tvd12.ezyfoxserver.socket.EzySocketStream) Test(org.testng.annotations.Test)

Example 7 with EzySocketStream

use of com.tvd12.ezyfoxserver.socket.EzySocketStream in project ezyfox-server by youngmonkeys.

the class EzySimpleWsHandlerGroup method handleReceivedBytes.

private void handleReceivedBytes(byte[] bytes, int offset, int len) {
    try {
        if (len <= 1) {
            return;
        }
        byte headerByte = bytes[offset];
        boolean isRawBytes = EzyMessageHeaderReader.readRawBytes(headerByte);
        if (isRawBytes) {
            boolean sessionStreamingEnable = session.isStreamingEnable();
            if (!streamingEnable || !sessionStreamingEnable) {
                return;
            }
            byte[] rawBytes = EzyBytes.copy(bytes, offset, len);
            EzySocketStream stream = new EzySimpleSocketStream(session, rawBytes);
            streamQueue.add(stream);
        } else {
            int newLen = len - 1;
            int newOffset = offset + 1;
            byte[] messageBytes = EzyBytes.copy(bytes, newOffset, newLen);
            handleReceivedBytes(messageBytes);
        }
    } catch (Throwable throwable) {
        fireExceptionCaught(throwable);
    }
}
Also used : EzySimpleSocketStream(com.tvd12.ezyfoxserver.socket.EzySimpleSocketStream) EzySocketStream(com.tvd12.ezyfoxserver.socket.EzySocketStream)

Aggregations

EzySession (com.tvd12.ezyfoxserver.entity.EzySession)4 Test (org.testng.annotations.Test)4 EzySocketStream (com.tvd12.ezyfoxserver.socket.EzySocketStream)3 EzySimpleSocketStream (com.tvd12.ezyfoxserver.socket.EzySimpleSocketStream)2 EzyBlockingSocketStreamQueue (com.tvd12.ezyfoxserver.socket.EzyBlockingSocketStreamQueue)1