Difference between revisions of "Peerd.c"
(move daemonise.c and servicate.c out and add launchd.c) |
m |
||
| Line 8: | Line 8: | ||
char *peer = "default"; | char *peer = "default"; | ||
| + | // Standard libraries | ||
#include <unistd.h> | #include <unistd.h> | ||
#include <stdlib.h> | #include <stdlib.h> | ||
#include <stdio.h> | #include <stdio.h> | ||
#include <string.h> | #include <string.h> | ||
| + | |||
| + | // Interface related | ||
#include "SDL/SDL.h" | #include "SDL/SDL.h" | ||
#include "SDL/SDL_image.h" | #include "SDL/SDL_image.h" | ||
| + | |||
| + | // Platform-dependent peer daemon setup | ||
#if __WIN32__ | #if __WIN32__ | ||
#include "servicate.c" | #include "servicate.c" | ||
| + | #elif __APPLE__ | ||
| + | #include "launchd.c" | ||
| + | #elif __UNIX__ | ||
| + | #include "daemonise.c" | ||
| + | #endif | ||
| + | |||
| + | // Network & server related | ||
| + | #if __WIN32__ | ||
#include <winsock2.h> | #include <winsock2.h> | ||
#else | #else | ||
| Line 25: | Line 38: | ||
#include <errno.h> | #include <errno.h> | ||
#endif | #endif | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
#include "server.c" | #include "server.c" | ||
Revision as of 05:44, 28 July 2006
// This article and all its includes are licenced under LGPL // GPL: http://www.gnu.org/copyleft/lesser.html // SRC: http://www.organicdesign.co.nz/husk.c
// Globals int port = 80; int this = 0; char *peer = "default";
// Standard libraries
- include <unistd.h>
- include <stdlib.h>
- include <stdio.h>
- include <string.h>
// Interface related
- include "SDL/SDL.h"
- include "SDL/SDL_image.h"
// Platform-dependent peer daemon setup
- if __WIN32__
- include "servicate.c"
- elif __APPLE__
- include "launchd.c"
- elif __UNIX__
- include "daemonise.c"
- endif
// Network & server related
- if __WIN32__
- include <winsock2.h>
- else
- include <sys/socket.h>
- include <sys/select.h>
- include <netinet/in.h>
- include <sys/time.h> // for select()
- include <fcntl.h> // O_RDWR, O_NONBLOCK, F_GETFL, F_SETFL
- include <errno.h>
- endif
- include "server.c"
int main(int argc, char **argv) {
#include "util.c" // General utils, file,log,string etc peerd_init(); // Set up as a daemon or service #include "listSpace.c" // listSpace and some C-specific extras: hash, trie, linked-list #include "args.c" // Handle command-line args and globals like peer and port #include "nodeSpace.c" // NodeSpace function declarations and initialisation #include "serialise.c" // Nodal-to-text and visa-versa #include "interface.c" // Layer model (currently bitmap/imagemap-based) server_init(); // Set up listening socket and declare serverIterate #include "nodalHusk.c" // Build initial nodal environment
if (errno == 0) { char *msg = malloc(100); sprintf(msg,"Daemon \"%s\" started successfully and serving on port %d.",peer,port); logAdd(msg); free(msg); }
// Main nodal reduction loop logAdd("Entering nodal reduction...\n"); while(nodeReduce(this=nodeROOT));
// Clean up all the mess and exit free(space); SDL_Quit(); #if __WIN32__ WSACleanup(); #endif return EXIT_SUCCESS;
}



