Cleaned up daemon.c
This commit is contained in:
parent
7d1215e8c4
commit
5458ba05b5
@ -25,24 +25,33 @@
|
|||||||
|
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#define CLOSE_SOCKET(socket) closesocket(socket)
|
|
||||||
#else
|
#else
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#define CLOSE_SOCKET(socket) close(socket)
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __HAVE_PTHREAD_H__
|
#ifdef HAVE_LIBPTHREAD
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#elif defined(__MINGW32)
|
#elif defined(__MINGW32__)
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <process.h>
|
#include <process.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
char error[65536];
|
#include <guacamole/client.h>
|
||||||
|
#include <guacamole/log.h>
|
||||||
|
|
||||||
|
/* Windows / MINGW32 handles closing sockets differently */
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
#define CLOSE_SOCKET(socket) closesocket(socket)
|
||||||
|
#else
|
||||||
|
#define CLOSE_SOCKET(socket) close(socket)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Cross-platform strerror()/errno clone */
|
||||||
|
char error[65536];
|
||||||
char* lasterror() {
|
char* lasterror() {
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
snprintf(error, sizeof(error)-1, "ERROR #%i", GetLastError());
|
snprintf(error, sizeof(error)-1, "ERROR #%i", GetLastError());
|
||||||
@ -52,8 +61,6 @@ char* lasterror() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <guacamole/client.h>
|
|
||||||
#include <guacamole/log.h>
|
|
||||||
|
|
||||||
typedef struct client_thread_data {
|
typedef struct client_thread_data {
|
||||||
|
|
||||||
@ -113,6 +120,11 @@ int main(int argc, char* argv[]) {
|
|||||||
/* Daemon Process */
|
/* Daemon Process */
|
||||||
pid_t daemon_pid;
|
pid_t daemon_pid;
|
||||||
|
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
/* Structure for holding winsock version info */
|
||||||
|
WSADATA wsadata;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Parse arguments */
|
/* Parse arguments */
|
||||||
while ((opt = getopt(argc, argv, "l:")) != -1) {
|
while ((opt = getopt(argc, argv, "l:")) != -1) {
|
||||||
if (opt == 'l') {
|
if (opt == 'l') {
|
||||||
@ -135,7 +147,7 @@ int main(int argc, char* argv[]) {
|
|||||||
server_addr.sin_port = htons(listen_port);
|
server_addr.sin_port = htons(listen_port);
|
||||||
|
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
WSADATA wsadata;
|
/* If compiling for Windows, init winsock. */
|
||||||
if (WSAStartup(MAKEWORD(1,1), &wsadata) == SOCKET_ERROR) {
|
if (WSAStartup(MAKEWORD(1,1), &wsadata) == SOCKET_ERROR) {
|
||||||
fprintf(stderr, "Error creating socket.");
|
fprintf(stderr, "Error creating socket.");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
@ -185,7 +197,7 @@ int main(int argc, char* argv[]) {
|
|||||||
/* Daemon loop */
|
/* Daemon loop */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
||||||
#ifdef pthread_t
|
#ifdef HAVE_LIBPTHREAD
|
||||||
pthread_t thread;
|
pthread_t thread;
|
||||||
#endif
|
#endif
|
||||||
client_thread_data* data;
|
client_thread_data* data;
|
||||||
@ -207,7 +219,7 @@ int main(int argc, char* argv[]) {
|
|||||||
data = malloc(sizeof(client_thread_data));
|
data = malloc(sizeof(client_thread_data));
|
||||||
data->fd = connected_socket_fd;
|
data->fd = connected_socket_fd;
|
||||||
|
|
||||||
#ifdef pthread_t
|
#ifdef HAVE_LIBPTHREAD
|
||||||
if (pthread_create(&thread, NULL, start_client_thread, (void*) data)) {
|
if (pthread_create(&thread, NULL, start_client_thread, (void*) data)) {
|
||||||
GUAC_LOG_ERROR("Could not create client thread: %s", lasterror());
|
GUAC_LOG_ERROR("Could not create client thread: %s", lasterror());
|
||||||
return 3;
|
return 3;
|
||||||
|
Loading…
Reference in New Issue
Block a user