support TCP sockets
This commit is contained in:
parent
219734a813
commit
971038fd4f
|
|
@ -14,10 +14,17 @@
|
||||||
#include <sys/epoll.h>
|
#include <sys/epoll.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/un.h>
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#define USE_UNIX_SOCKET 1
|
||||||
|
|
||||||
|
#if USE_UNIX_SOCKET
|
||||||
|
#include <sys/un.h>
|
||||||
|
#else
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <X11/keysym.h>
|
#include <X11/keysym.h>
|
||||||
#include <X11/X.h>
|
#include <X11/X.h>
|
||||||
#include <X11/Xatom.h>
|
#include <X11/Xatom.h>
|
||||||
|
|
@ -2561,23 +2568,37 @@ int main()
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if USE_UNIX_SOCKET
|
||||||
int server_sock = socket(AF_UNIX, SOCK_STREAM, 0);
|
int server_sock = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
|
#else
|
||||||
|
int server_sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
|
#endif
|
||||||
if (server_sock == -1)
|
if (server_sock == -1)
|
||||||
{
|
{
|
||||||
perror("xbanan: socket");
|
perror("xbanan: socket");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if USE_UNIX_SOCKET
|
||||||
const sockaddr_un addr {
|
const sockaddr_un addr {
|
||||||
.sun_family = AF_UNIX,
|
.sun_family = AF_UNIX,
|
||||||
.sun_path = "/tmp/.X11-unix/X69"
|
.sun_path = "/tmp/.X11-unix/X69"
|
||||||
};
|
};
|
||||||
|
#else
|
||||||
|
const sockaddr_in addr {
|
||||||
|
.sin_family = AF_INET,
|
||||||
|
.sin_port = htons(6069),
|
||||||
|
.sin_addr = htonl(INADDR_LOOPBACK),
|
||||||
|
};
|
||||||
|
#endif
|
||||||
if (bind(server_sock, reinterpret_cast<const sockaddr*>(&addr), sizeof(addr)) == -1)
|
if (bind(server_sock, reinterpret_cast<const sockaddr*>(&addr), sizeof(addr)) == -1)
|
||||||
{
|
{
|
||||||
perror("xbanan: bind");
|
perror("xbanan: bind");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
#if USE_UNIX_SOCKET
|
||||||
atexit([] { unlink("/tmp/.X11-unix/X69"); });
|
atexit([] { unlink("/tmp/.X11-unix/X69"); });
|
||||||
|
#endif
|
||||||
|
|
||||||
if (listen(server_sock, SOMAXCONN) == -1)
|
if (listen(server_sock, SOMAXCONN) == -1)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue