mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
Core: UnixSocket (AF_UNIX) implementation (#325)
* Core: UnixSocket (AF_UNIX) implementation Core/UnixSocket: GetPeerPid refactored reference/UnixSocketClient: Use default socket type for connection reference/UnixSocketServer: Use default socket type for listen Core: UnixSocket API docs & cleanup Core: UnixSocket friend declaration guarded using ifdefs. * Core: UnixSocket, GetPeerPid() refactored, docs updated * Core: TcpSocket renamed as Socket and added unix domain socket support. Cleanup Updated API docs. * Core: UnixSocket entry removed from API docs. * Core: Socket/SocketWaitEvent API docs cosmetics. * Core: Socket cosmetics
This commit is contained in:
parent
09a272d7f7
commit
962dd7f37c
12 changed files with 537 additions and 184 deletions
51
autotest/UnixSocket/UnixSocket.cpp
Normal file
51
autotest/UnixSocket/UnixSocket.cpp
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
#include <Core/Core.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
CONSOLE_APP_MAIN
|
||||
{
|
||||
#ifdef PLATFORM_POSIX
|
||||
|
||||
StdLogSetup(LOG_COUT|LOG_FILE);
|
||||
|
||||
String path = Format("/tmp/upp-unixsocket-test-%d", getpid());
|
||||
|
||||
Socket server, client;
|
||||
|
||||
// Test server listen
|
||||
if(!server.ListenFileSystem(path)) {
|
||||
LOG("Server listen failed: " << server.GetErrorDesc());
|
||||
Exit(1);
|
||||
}
|
||||
|
||||
// Test client connect
|
||||
if(!client.ConnectFileSystem(path)) {
|
||||
LOG("Client connect failed: " << client.GetErrorDesc());
|
||||
Exit(1);
|
||||
}
|
||||
|
||||
// Test data exchange
|
||||
String test_data = "Hello, world!";
|
||||
client.Put(test_data + "\n");
|
||||
|
||||
Socket accepted;
|
||||
if(!accepted.Accept(server)) {
|
||||
LOG("Accept failed: " << accepted.GetErrorDesc());
|
||||
Exit(1);
|
||||
}
|
||||
|
||||
String received = accepted.GetLine();
|
||||
DUMP(received);
|
||||
|
||||
ASSERT(received == test_data);
|
||||
|
||||
// Test peer PID (on supported platforms)
|
||||
int pid = accepted.GetPeerPid();
|
||||
DUMP(pid);
|
||||
if(pid != -1)
|
||||
ASSERT(pid == getpid()); // Should be our own process in this test
|
||||
|
||||
LOG("=========== OK");
|
||||
|
||||
#endif
|
||||
}
|
||||
9
autotest/UnixSocket/UnixSocket.upp
Normal file
9
autotest/UnixSocket/UnixSocket.upp
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
uses
|
||||
Core;
|
||||
|
||||
file
|
||||
UnixSocket.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "";
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue