Difference between revisions of "Peerd.c"

From Organic Design wiki
m
(all definitions out of main())
Line 7: Line 7:
 
int this = 0;
 
int this = 0;
 
char *peer = "default";
 
char *peer = "default";
 +
 +
// These are tmp until pointer-list used
 +
char *nssBuf = malloc(20);
 +
int hashPtr = 0;
 +
void **hashBuf = malloc(HASHBUFSIZE);
  
 
// Standard & general
 
// Standard & general
Line 40: Line 45:
 
#endif
 
#endif
 
#include "server.c"
 
#include "server.c"
 +
 +
// List & Node Space
 +
#include "listSpace.c"      // listSpace and some C-specific extras: hash, trie, linked-list
 +
#include "nodeSpace.c"      // NodeSpace function declarations and initialisation
 +
#include "serialise.c"      // Nodal-to-text and visa-versa
 +
#include "nodalHusk.c"      // Build initial nodal environment
 +
#include "interface.c"      // Layer model (currently bitmap/imagemap-based)
 +
  
 
int main(int argc, char **argv) {
 
int main(int argc, char **argv) {
  
logAdd("");            // Enter a blank line in log as a marker of new peerd session
 
 
peerd_init();          // Set up as a daemon or service
 
peerd_init();          // Set up as a daemon or service
#include "listSpace.c"  // listSpace and some C-specific extras: hash, trie, linked-list
+
list_init();            // Initialise list-space and hash/trie functions
#include "args.c"      // Handle command-line args and globals like peer and port
+
args()                  // Handle command-line args and globals like peer and port
#include "nodeSpace.c"  // NodeSpace function declarations and initialisation
+
interface_init();      // Initialise SDL surface
#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
 
server_init();          // Set up listening socket and declare serverIterate
#include "nodalHusk.c"  // Build initial nodal environment
+
nodal_init();          // Set up initial nodal structure for reduction loop
  
 
// Main nodal reduction loop
 
// Main nodal reduction loop
logAdd("Entering nodal reduction...\n");
+
logAdd("\nEntering nodal reduction...\n");
 
while(nodeReduce(this=nodeROOT));
 
while(nodeReduce(this=nodeROOT));
  
 
// Clean up all the mess and exit
 
// Clean up all the mess and exit
free(space);
+
interface_exit();
SDL_Quit();
+
server_exit();
#if __WIN32__
+
list_exit();
WSACleanup();
 
#endif
 
 
return EXIT_SUCCESS;
 
return EXIT_SUCCESS;
  
 
}
 
}

Revision as of 06:24, 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";

// These are tmp until pointer-list used char *nssBuf = malloc(20); int hashPtr = 0; void **hashBuf = malloc(HASHBUFSIZE);

// Standard & general

  1. include <unistd.h>
  2. include <stdlib.h>
  3. include <stdio.h>
  4. include <string.h>
  5. include "util.c" // General utils, file,log,string etc

// Interface related

  1. include "SDL/SDL.h"
  2. include "SDL/SDL_image.h"

// Peer daemon setup

  1. if __WIN32__
  2. include "servicate.c"
  3. elif __APPLE__
  4. include "launchd.c"
  5. elif __UNIX__
  6. include "daemonise.c"
  7. endif

// Network & server related

  1. if __WIN32__
  2. include <winsock2.h>
  3. else
  4. include <sys/socket.h>
  5. include <sys/select.h>
  6. include <netinet/in.h>
  7. include <sys/time.h> // for select()
  8. include <fcntl.h> // O_RDWR, O_NONBLOCK, F_GETFL, F_SETFL
  9. include <errno.h>
  10. endif
  11. include "server.c"

// List & Node Space

  1. include "listSpace.c" // listSpace and some C-specific extras: hash, trie, linked-list
  2. include "nodeSpace.c" // NodeSpace function declarations and initialisation
  3. include "serialise.c" // Nodal-to-text and visa-versa
  4. include "nodalHusk.c" // Build initial nodal environment
  5. include "interface.c" // Layer model (currently bitmap/imagemap-based)


int main(int argc, char **argv) {

peerd_init(); // Set up as a daemon or service list_init(); // Initialise list-space and hash/trie functions args() // Handle command-line args and globals like peer and port interface_init(); // Initialise SDL surface server_init(); // Set up listening socket and declare serverIterate nodal_init(); // Set up initial nodal structure for reduction loop

// Main nodal reduction loop logAdd("\nEntering nodal reduction...\n"); while(nodeReduce(this=nodeROOT));

// Clean up all the mess and exit interface_exit(); server_exit(); list_exit(); return EXIT_SUCCESS;

}