Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

network_unix.cpp

Go to the documentation of this file.
00001 /*
00002         $Id: network_unix.cpp,v 1.2 2001/02/23 00:04:50 cybernerd Exp $
00003 
00004         ------------------------------------------------------------------------
00005         ClanLib, the platform independent game SDK.
00006 
00007         This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
00008         version 2. See COPYING for details.
00009 
00010         For a total list of contributers see CREDITS.
00011 
00012         ------------------------------------------------------------------------
00013 */
00014 
00015 #include "Core/precomp.h"
00016 
00017 #ifdef USE_NETWORK
00018 
00019 #include <iostream>
00020 #include <netdb.h>
00021 #include <signal.h>
00022 
00023 #include <Network/Generic/network_generic.h>
00024 #include <Network/Unix/connection_provider_unix.h>
00025 #include <Network/Unix/network_unix.h>
00026 #include <Core/System/Unix/implementation.h>
00027 
00028 void signal_pipe(int)
00029 {
00030 /*
00031         delete CL_Implementation_Network::delivery;
00032         exit(0); // bye bye
00033 */
00034         // hmm - who cares!
00035 }
00036 
00037 CL_Network_Generic *CL_Network_Unix::network = NULL;
00038 
00039 extern "C"
00040 {
00041         DL_PREFIX char *clan_module_identify() {
00042                 return "Clanlib Network implementation";
00043         }
00044 
00045         DL_PREFIX char *clan_module_abbreviation() {
00046                 return "net";
00047         }
00048 
00049         DL_PREFIX void clan_module_init() {
00050                 CL_Implementation_Network::add_network();
00051         }
00052 }
00053 
00054 char *network_identify() {
00055   return clan_module_identify();
00056 }
00057 
00058 char *network_abbreviation() {
00059   return clan_module_abbreviation();
00060 }
00061 
00062 void network_init() {
00063   clan_module_init();
00064 }
00065 
00066 
00067 /*
00068 void CL_Implementation_Network::add_network()
00069 {
00070         char name[100];
00071         gethostname(name, 100);
00072 
00073         hostent *ent = gethostbyname(name);
00074 
00075         unsigned long local_ip = *((unsigned long *) *ent->h_addr_list);
00076 
00077         int pipes[4];
00078         pipe(pipes);
00079         pipe(&pipes[2]);
00080 
00081         int our_pid = getpid();
00082         if (fork()==0)
00083         {
00084                 CL_UnixPipeConnection *delivery = new CL_UnixPipeConnection(pipes[0], pipes[3]);
00085                 CL_Network_Unix::network = new CL_Network_Generic(local_ip, our_pid, delivery);
00086 
00087                 CL_System_Generic::keep_alives.add(new CL_Network_Unix);
00088         }
00089         else
00090         {
00091                 signal(SIGPIPE, signal_pipe);
00092                 signal(SIGHUP, signal_pipe);
00093                 signal(SIGCHLD, signal_pipe);
00094                 signal(SIGTERM, signal_pipe);
00095 
00096                 CL_ComputerID our_id;
00097                 our_id.ip_addr = local_ip;
00098                 our_id.pid = our_pid;
00099 
00100                 CL_UnixPipeConnection delivery_connection(pipes[2], pipes[1]);
00101                 CL_Connections_Unix *connections = new CL_Connections_Unix(&delivery_connection);
00102                 
00103                 delivery = new CL_NetDelivery(connections, our_id);
00104                 delivery->run();
00105                 delete delivery;
00106 
00107                 exit(0);
00108         }
00109 }
00110 */
00111 
00112 void CL_Implementation_Network::add_network()
00113 {
00114         CL_Connections_Unix *connections = new CL_Connections_Unix(NULL);
00115 
00116         signal(SIGPIPE, signal_pipe);
00117 
00118         CL_Network_Unix::network = new CL_Network_Generic(connections);
00119 }
00120 
00121 void CL_Implementation_Network::remove_network()
00122 {
00123         if (CL_Network_Unix::network != NULL) delete CL_Network_Unix::network;
00124         CL_Network_Unix::network = NULL;
00125 }
00126 
00127 #endif // USE_NETWORK

Generated at Wed Apr 4 19:54:02 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001