Difference between revisions of "Peerd.c"
(define globals at start) |
(oops, must have pasted wrong code) |
||
| Line 1: | Line 1: | ||
// This article and all its includes are licenced under LGPL | // This article and all its includes are licenced under LGPL | ||
// GPL: http://www.gnu.org/copyleft/lesser.html | // GPL: http://www.gnu.org/copyleft/lesser.html | ||
| − | // SRC: http://www.organicdesign.co.nz/ | + | // SRC: http://www.organicdesign.co.nz/husk.c |
| − | # | + | #include <unistd.h> |
| − | # | + | #include <stdlib.h> |
| − | # | + | #include <stdio.h> |
| − | # | + | #include <string.h> |
| + | #include "SDL/SDL.h" | ||
| + | #include "SDL/SDL_image.h" | ||
| + | #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 | ||
| + | #endif | ||
| − | // | + | // Globals |
| − | + | int port = 8000; | |
| − | + | int err = 0; | |
| − | + | int this = 0; | |
| − | + | char *peer = "test"; | |
| − | int | + | // |
| − | + | int main(int argc, char **argv) { | |
| − | |||
| − | |||
| − | |||
| − | // | + | #include "util.c" // General utils, file,log,string etc |
| − | |||
| − | |||
| − | |||
| − | |||
| − | // | + | #if __WIN32__ // Set up as a daemon or service |
| − | + | #include "servicate.c" | |
| − | + | #elif __UNIX__ | |
| − | # | + | #include "daemonise.c" |
| − | |||
| − | # | ||
| − | |||
#endif | #endif | ||
| − | |||
| − | |||
| − | // | + | #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) | |
| − | + | #include "server.c" // Set up listening socket and declare serverIterate | |
| − | + | #include "nodalHusk.c" // Build initial nodal environment | |
| − | |||
| − | |||
| − | + | if (err == 0) { | |
| − | + | char *msg = malloc(100); | |
| − | + | sprintf(msg,"Daemon \"%s\" started successfully and serving on port %d.",peer,port); | |
| − | + | logAdd(msg); | |
| − | + | free(msg); | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
} | } | ||
| − | |||
| − | + | logAdd("Entering nodal reduction...\n"); | |
| − | + | while(nodeReduce(this=ROOT)); | |
| − | + | free(space); | |
| − | + | SDL_Quit(); | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
} | } | ||
Revision as of 10:00, 25 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
- include <unistd.h>
- include <stdlib.h>
- include <stdio.h>
- include <string.h>
- include "SDL/SDL.h"
- include "SDL/SDL_image.h"
- 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
- endif
// Globals int port = 8000; int err = 0; int this = 0; char *peer = "test"; // int main(int argc, char **argv) {
#include "util.c" // General utils, file,log,string etc
#if __WIN32__ // Set up as a daemon or service #include "servicate.c" #elif __UNIX__ #include "daemonise.c" #endif
#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) #include "server.c" // Set up listening socket and declare serverIterate #include "nodalHusk.c" // Build initial nodal environment
if (err == 0) {
char *msg = malloc(100);
sprintf(msg,"Daemon \"%s\" started successfully and serving on port %d.",peer,port);
logAdd(msg);
free(msg);
}
logAdd("Entering nodal reduction...\n"); while(nodeReduce(this=ROOT)); free(space); SDL_Quit();
}



