Difference between revisions of "Peerd.c"

From Organic Design wiki
m
m
Line 2: Line 2:
 
// GPL: http://www.gnu.org/copyleft/lesser.html
 
// GPL: http://www.gnu.org/copyleft/lesser.html
 
// SRC: http://www.organicdesign.co.nz/husk.c
 
// SRC: http://www.organicdesign.co.nz/husk.c
 +
 +
// Globals
 +
int port = 80;
 +
int this = 0;
 +
char *peer = "default";
  
 
#include <unistd.h>
 
#include <unistd.h>
Line 10: Line 15:
 
#include "SDL/SDL_image.h"
 
#include "SDL/SDL_image.h"
 
#if __WIN32__
 
#if __WIN32__
 +
#include "servicate.c"
 
#include <winsock2.h>
 
#include <winsock2.h>
 
#else
 
#else
Line 18: Line 24:
 
#include <fcntl.h>      // O_RDWR, O_NONBLOCK, F_GETFL, F_SETFL
 
#include <fcntl.h>      // O_RDWR, O_NONBLOCK, F_GETFL, F_SETFL
 
#include <errno.h>
 
#include <errno.h>
 +
#endif
 +
#if __UNIX__
 +
#include "daemonise.c"
 
#endif
 
#endif
  
// Globals
+
#include "server.c"
int port = 80;
 
int this = 0;
 
char *peer = "default";
 
  
 
int main(int argc, char **argv) {
 
int main(int argc, char **argv) {
Line 30: Line 36:
  
 
#if __WIN32__          // Set up as a daemon or service
 
#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 "listSpace.c"  // listSpace and some C-specific extras: hash, trie, linked-list
Line 40: Line 42:
 
#include "serialise.c"  // Nodal-to-text and visa-versa
 
#include "serialise.c"  // Nodal-to-text and visa-versa
 
#include "interface.c"  // Layer model (currently bitmap/imagemap-based)
 
#include "interface.c"  // Layer model (currently bitmap/imagemap-based)
#include "server.c"    // Set up listening socket and declare serverIterate
+
server_init();          // Set up listening socket and declare serverIterate
 
#include "nodalHusk.c"  // Build initial nodal environment
 
#include "nodalHusk.c"  // Build initial nodal environment
  

Revision as of 05:29, 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";

  1. include <unistd.h>
  2. include <stdlib.h>
  3. include <stdio.h>
  4. include <string.h>
  5. include "SDL/SDL.h"
  6. include "SDL/SDL_image.h"
  7. if __WIN32__
  8. include "servicate.c"
  9. include <winsock2.h>
  10. else
  11. include <sys/socket.h>
  12. include <sys/select.h>
  13. include <netinet/in.h>
  14. include <sys/time.h> // for select()
  15. include <fcntl.h> // O_RDWR, O_NONBLOCK, F_GETFL, F_SETFL
  16. include <errno.h>
  17. endif
  18. if __UNIX__
  19. include "daemonise.c"
  20. endif
  1. include "server.c"

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 "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;

}