projects
/
guacd.git
/ commitdiff
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
db5c2e9
)
Cleaned up daemon.c
author
Michael Jumper <zhangmaike@users.sourceforge.net>
Fri, 11 Feb 2011 07:47:46 +0000
(23:47 -0800)
committer
Michael Jumper <zhangmaike@users.sourceforge.net>
Fri, 11 Feb 2011 07:47:46 +0000
(23:47 -0800)
src/daemon.c
patch
|
blob
|
history
diff --git
a/src/daemon.c
b/src/daemon.c
index
bdc0a0d
..
c734061
100644
(file)
--- a/
src/daemon.c
+++ b/
src/daemon.c
@@
-25,24
+25,33
@@
#ifdef __MINGW32__
#include <winsock2.h>
#ifdef __MINGW32__
#include <winsock2.h>
-#define CLOSE_SOCKET(socket) closesocket(socket)
#else
#include <sys/socket.h>
#include <netinet/in.h>
#else
#include <sys/socket.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 <process.h>
#endif
#include <errno.h>
#include <windows.h>
#include <process.h>
#endif
#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() {
#ifdef __MINGW32__
snprintf(error, sizeof(error)-1, "ERROR #%i", GetLastError());
char* lasterror() {
#ifdef __MINGW32__
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 */
pid_t daemon_pid;
/* Daemon Process */
pid_t daemon_pid;
+#ifdef __MINGW32__
+ /* Structure for holding winsock version info */
+ WSADATA wsadata;
+#endif
+
/* Parse arguments */
while ((opt = getopt(argc, argv, "l:")) != -1) {
if (opt == 'l') {
/* Parse arguments */
while ((opt = getopt(argc, argv, "l:")) != -1) {
if (opt == 'l') {
@@
-135,7
+147,7
@@
int main(int argc, char* argv[]) {
server_addr.sin_port = htons(listen_port);
#ifdef __MINGW32__
server_addr.sin_port = htons(listen_port);
#ifdef __MINGW32__
- WSADATA wsadata;
+ /* If compiling for Windows, init winsock. */
if (WSAStartup(MAKEWORD(1,1), &wsadata) == SOCKET_ERROR) {
fprintf(stderr, "Error creating socket.");
exit(EXIT_FAILURE);
if (WSAStartup(MAKEWORD(1,1), &wsadata) == SOCKET_ERROR) {
fprintf(stderr, "Error creating socket.");
exit(EXIT_FAILURE);
@@
-185,7
+197,7
@@
int main(int argc, char* argv[]) {
/* Daemon loop */
for (;;) {
/* Daemon loop */
for (;;) {
-#ifdef pthread_t
+#ifdef HAVE_LIBPTHREAD
pthread_t thread;
#endif
client_thread_data* data;
pthread_t thread;
#endif
client_thread_data* data;
@@
-207,7
+219,7
@@
int main(int argc, char* argv[]) {
data = malloc(sizeof(client_thread_data));
data->fd = connected_socket_fd;
data = malloc(sizeof(client_thread_data));
data->fd = connected_socket_fd;
-#ifdef pthread_t
+#ifdef HAVE_LIBPTHREAD
if (pthread_create(&thread, NULL, start_client_thread, (void*) data)) {
GUAC_LOG_ERROR("Could not create client thread: %s", lasterror());
return 3;
if (pthread_create(&thread, NULL, start_client_thread, (void*) data)) {
GUAC_LOG_ERROR("Could not create client thread: %s", lasterror());
return 3;