use of io.questdb.std.str.NativeLPSZ in project questdb by bluestreak01.
the class NetTest method testSeek.
@Test
public void testSeek() {
int port = 9993;
NativeLPSZ lpsz = new NativeLPSZ();
String msg = "Test ABC";
CharSequenceZ charSink = new CharSequenceZ(msg);
int msgLen = charSink.length() + 1;
long acceptFd = Net.socketTcp(true);
Assert.assertTrue(acceptFd > 0);
Assert.assertTrue(Net.bindTcp(acceptFd, 0, port));
Net.listen(acceptFd, 1024);
long clientFd = Net.socketTcp(true);
long sockAddr = Net.sockaddr("127.0.0.1", port);
TestUtils.assertConnect(clientFd, sockAddr);
Assert.assertEquals(msgLen, Net.send(clientFd, charSink.address(), msgLen));
Net.close(clientFd);
Net.freeSockAddr(sockAddr);
long serverFd = Net.accept(acceptFd);
long serverBuf = Unsafe.malloc(msgLen, MemoryTag.NATIVE_DEFAULT);
Assert.assertEquals(msgLen, Net.peek(serverFd, serverBuf, msgLen));
lpsz.of(serverBuf);
Assert.assertEquals(msg, lpsz.toString());
Assert.assertEquals(msgLen, Net.recv(serverFd, serverBuf, msgLen));
lpsz.of(serverBuf);
Assert.assertEquals(msg, lpsz.toString());
Unsafe.free(serverBuf, msgLen, MemoryTag.NATIVE_DEFAULT);
Net.close(serverFd);
Net.close(acceptFd);
charSink.close();
}
Aggregations