Changeset - e17b86eab31c
[Not reviewed]
default
0 2 3
Nathan Brink (binki) - 16 years ago 2009-11-27 11:52:08
ohnobinki@ohnopublishing.net
reorganized listening functions, socket listen()ed to
5 files changed with 185 insertions and 34 deletions:
0 comments (0 inline, 0 general)
src/server/Makefile.am
Show inline comments
 
COMMON_SOURCES =  slavefuncs.c slavefuncs.h distrenjob.c distrenjob.h
 

	
 
bin_PROGRAMS = distrend distrenslave
 
distrend_SOURCES = distrend.c ${COMMON_SOURCES} user_mgr.c user_mgr.h
 
distrend_SOURCES = distrend.c distrend.h ${COMMON_SOURCES} user_mgr.c user_mgr.h listen.h listen.c
 
distrend_LDADD = @DISTLIBS_LIBS@ @top_builddir@/src/common/libdistrencommon.la @LIST_LIBS@
 
distrend_CFLAGS = @DISTLIBS_CFLAGS@ -I@top_srcdir@/src/common
 

	
 
distrenslave_SOURCES = slave.c ${COMMON_SOURCES}
 
distrenslave_LDADD = @DISTLIBS_LIBS@ @top_builddir@/src/common/libdistrencommon.la
 
distrenslave_CFLAGS = @DISTLIBS_CFLAGS@ -I@top_srcdir@/src/common
src/server/distrend.c
Show inline comments
 
@@ -25,12 +25,13 @@
 
 */
 
#define _GNU_SOURCE 1
 

	
 
#include "execio.h"
 
#include "options.h"
 
#include "distrenjob.h"
 
#include "listen.h"
 
#include "protocol.h"
 
#include "slavefuncs.h"
 
#include "asprintf.h"
 

	
 
#include <confuse.h>
 
#include <stdio.h>
 
@@ -47,21 +48,12 @@
 
#include <libxml/encoding.h>
 
#include <libxml/xmlwriter.h>
 
#include <libxml/xmlreader.h>
 

	
 
/* ******************* Structs ************************ */
 

	
 
// Gets config info from confs
 
struct distrend_config
 
{
 
  cfg_t *mycfg;
 
  struct options_common *options;
 
  struct distrend_listen **listens; /*< Null terminated array of structs */
 
  char *datadir;
 
};
 

	
 
struct general_info {
 
  short int jobs_in_queue; //
 
  unsigned short int free_clients;
 
  unsigned short int rendering_clients;//
 
  unsigned short int total_finished_jobs; //
 
  unsigned int total_frames_rendered; //
 
@@ -121,33 +113,12 @@ void distrend_accept()
 
   Frees the action
 
*/
 
void distrend_action_free()
 
{
 

	
 
}
 
/**
 
   Start listening
 
*/
 
void distrend_listen()
 
{
 

	
 
}
 
/**
 
   Stop listening
 
*/
 
void distrend_unlisten()
 
{
 

	
 
}
 
/**
 
   This is probably just a placeholder for remotio
 
*/
 
void remotio_send_to_client()
 
{
 
	// I am futile!
 
}
 

	
 
/** Fill variables after crash / shutdown from XML dumps */
 
int start_data(struct distrenjob *head, char *datadir)
 
{
 
  struct stat buffer;
 
  if(stat("general_info.xml", &buffer) == 0){
 
@@ -1069,13 +1040,13 @@ int main(int argc, char *argv[])
 
  int test; // Interactive test mode if 1
 

	
 

	
 
  struct distrenjob head;
 

	
 
  int cont;
 
  struct distrend_listenset *listenset;
 
  struct distrend_clientset *clients;
 
  struct distrend_config *config;
 

	
 
  enum clientstatus
 
  {
 
    CLIENTSTATUS_UNINITIALIZED = 0,
 
    CLIENTSTATUS_BUSY = 1,
 
@@ -1214,13 +1185,13 @@ int main(int argc, char *argv[])
 
      return 0;
 
    default:
 
      fprintf(stderr, "Invalid input, please try again.\n");
 
    }
 
  }
 

	
 
  distrend_listen(&listenset, config);
 
  distrend_listen(config, &clients);
 
  /* This is called the "main loop" */
 
  while(cont)
 
    {
 
      struct distren_action *action;
 
      int clientsays = 0; /*< temporary example variable, will be replaced when we can handle messages */
 

	
 
@@ -1252,13 +1223,13 @@ int main(int argc, char *argv[])
 
      	  finish_frame(&head, job, frame->num); // @TODO: Make sure this actually works.
 
      	}
 

	
 
      distrend_action_free(action);
 
    }
 

	
 
  distrend_unlisten(listenset);
 
  distrend_unlisten(config->listens, clients);
 
  distrend_config_free(config);
 

	
 
  xmlcleanup();
 

	
 
  return 0;
 
}
src/server/distrend.h
Show inline comments
 
new file 100644
 
/*
 
  Copyright 2009 Nathan Phillip Brink
 

	
 
  This file is a part of DistRen.
 

	
 
  DistRen is free software: you can redistribute it and/or modify
 
  it under the terms of the GNU Affero General Public License as published by
 
  the Free Software Foundation, either version 3 of the License, or
 
  (at your option) any later version.
 

	
 
  DistRen is distributed in the hope that it will be useful,
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  GNU Affero General Public License for more details.
 

	
 
  You should have received a copy of the GNU Affero General Public License
 
  along with DistRen.  If not, see <http://www.gnu.org/licenses/>.
 

	
 
*/
 

	
 
struct distrend_config;
 

	
 
#ifndef _DISTREN_DISTREN_H_
 
#define _DISTREN_DISTREN_H_
 

	
 
#include <confuse.h>
 

	
 
#include "listen.h"
 

	
 
struct distrend_config
 
{
 
  cfg_t *mycfg;
 
  struct options_common *options;
 
  struct distrend_listen *listens; /*< Null terminated array of structs */
 
  char *datadir;
 
};
 

	
 

	
 
#endif
src/server/listen.c
Show inline comments
 
new file 100644
 
/*
 
  Copyright 2009 Nathan Phillip Brink
 

	
 
  This file is a part of DistRen.
 

	
 
  DistRen is free software: you can redistribute it and/or modify
 
  it under the terms of the GNU Affero General Public License as published by
 
  the Free Software Foundation, either version 3 of the License, or
 
  (at your option) any later version.
 

	
 
  DistRen is distributed in the hope that it will be useful,
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  GNU Affero General Public License for more details.
 

	
 
  You should have received a copy of the GNU Affero General Public License
 
  along with DistRen.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#include "listen.h"
 

	
 
#include <list.h>
 
#include <malloc.h>
 
#include <netinet/in.h>
 
#include <stdio.h>
 
#include <sys/types.h>
 
#include <sys/socket.h>
 

	
 
/* local */
 

	
 
struct distrend_client
 
{
 
  int sock;
 
  int state;
 
};
 

	
 
struct distrend_clientset
 
{
 
  LIST *clients;
 
};
 

	
 

	
 
int distrend_listen(struct distrend_config *config, struct distrend_clientset **clients)
 
{
 
  int tmp;
 

	
 
  struct sockaddr_in6 sockaddr =
 
    {
 
      .sin6_family = AF_INET6,
 
      .sin6_port = 0,
 
      .sin6_flowinfo = 0,
 
      .sin6_addr = IN6ADDR_ANY_INIT,
 
      .sin6_scope_id = 0
 
    };
 

	
 
  *clients = malloc(sizeof(struct distrend_clientset));
 

	
 
  (*clients)->clients = list_init();
 

	
 
  sockaddr.sin6_port = htonl(4050);
 

	
 
  config->listens->sock = socket(AF_INET6, SOCK_STREAM, 0);
 
  tmp = bind(config->listens->sock, (struct sockaddr *)&sockaddr, sizeof(sockaddr));
 
  if(tmp == -1)
 
    {
 
      perror("bind");
 
      free(*clients);
 

	
 
      return 1;
 
    }
 

	
 
  tmp = listen(config->listens->sock, 1);
 

	
 
  return 0;
 
}
 

	
 
int distrend_unlisten(struct distrend_listen *listens, struct distrend_clientset *clients)
 
{
 
  fprintf(stderr, "%s:%d: I am a stub that needn't be implemented 'til later\n", __FILE__, __LINE__);
 

	
 
  return 1;
 
}
 
/**
 
   This is probably just NOT a placeholder for remotio
 
*/
 
void remotio_send_to_client()
 
{
 
  fprintf(stderr, "%s:%d: I am futile! And I'm happy because of it :-D\n", __FILE__, __LINE__);
 
}
src/server/listen.h
Show inline comments
 
new file 100644
 
/*
 
  Copyright 2009 Nathan Phillip Brink
 

	
 
  This file is a part of DistRen.
 

	
 
  DistRen is free software: you can redistribute it and/or modify
 
  it under the terms of the GNU Affero General Public License as published by
 
  the Free Software Foundation, either version 3 of the License, or
 
  (at your option) any later version.
 

	
 
  DistRen is distributed in the hope that it will be useful,
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  GNU Affero General Public License for more details.
 

	
 
  You should have received a copy of the GNU Affero General Public License
 
  along with DistRen.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
struct distrend_clientset;
 
struct distrend_listen;
 

	
 
#ifndef _DISTREN_LISTEN_H
 
#define _DISTREN_LISTEN_H
 

	
 
#include "distrend.h"
 

	
 
struct distrend_listen
 
{
 
  int port;
 
  int sock;
 
};
 

	
 

	
 
/**
 
   initializes the listens and clientset
 
   @param config the configuration from distrend
 
   @param clients a pointer to a struct distrend_clientset pointer which will be set to memory allocated for the clientset
 
 */
 
int distrend_listen(struct distrend_config *config, struct distrend_clientset **clients);
 

	
 
/**
 
   cleans listening socket. Unnecessary for a working server, currently a stub.
 
 */
 
int distrend_unlisten(struct distrend_listen *listens, struct distrend_clientset *clients);
 

	
 
/**
 
   This is probably just NOT a placeholder for remotio
 
*/
 
void remotio_send_to_client();
 

	
 
#endif
0 comments (0 inline, 0 general)