mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
* 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
33 lines
693 B
C++
33 lines
693 B
C++
#include <Core/Core.h>
|
|
|
|
using namespace Upp;
|
|
|
|
CONSOLE_APP_MAIN
|
|
{
|
|
#ifdef PLATFORM_POSIX
|
|
const String& path = "/tmp/upp-unixsocket.sock";
|
|
|
|
Socket server;
|
|
if(!server.ListenFileSystem(path, 5)) {
|
|
Cout() << "Unable to initialize server socket!\n";
|
|
SetExitCode(1);
|
|
return;
|
|
}
|
|
Cout() << "Waiting for requests..\n";
|
|
for(;;) {
|
|
Socket s;
|
|
if(s.Accept(server)) {
|
|
String w = s.GetLine();
|
|
Cout() << "Request: " << w << " from: " << s.GetPeerPid() << '\n';
|
|
if(w == "time")
|
|
s.Put(AsString(GetSysTime()));
|
|
else
|
|
s.Put(AsString(3 * atoi(~w)));
|
|
s.Put("\n");
|
|
}
|
|
}
|
|
#else
|
|
Cout() << "This example requires a POSIX compliant operating system...\r\n"
|
|
SetExitCode(1);
|
|
#endif
|
|
}
|