Changeset - 4f50bc8e5de6
[Not reviewed]
default
0 4 0
Nathan Brink (binki) - 16 years ago 2010-01-03 12:39:20
ohnobinki@ohnopublishing.net
remove struct distrend_action, improve distrend_accept()
4 files changed with 75 insertions and 38 deletions:
0 comments (0 inline, 0 general)
src/server/distrend.c
Show inline comments
 
@@ -101,13 +101,6 @@ int distrend_do()
 
{
 
  return 0;
 
}
 
/**
 
   Frees the action. @TODO: Fill stub
 
*/
 
void distrend_action_free()
 
{
 

	
 
}
 

	
 
/** 
 
    Fill variables at startup from XML dumps or defaults
 
@@ -1280,13 +1273,11 @@ int main(int argc, char *argv[])
 

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

	
 
      distrend_accept(general_info.config, clients, &action);
 
      cont = distrend_do(action);
 
      distrend_accept(general_info.config, clients);
 

	
 
      /* Make the following code more event-driven */
 
      frame_watchdog(&general_info.head);
 
@@ -1312,9 +1303,7 @@ int main(int argc, char *argv[])
 
      	  clientstatus = CLIENTSTATUS_IDLE; // Sets the client back to idle
 
      	  finish_frame(&general_info, job, frame->num); // @TODO: Make sure this actually works.
 
      	}
 

	
 
      distrend_action_free(action);
 
    }
 
    } /* while(!general_info.config->die) */
 

	
 
  distrend_unlisten(general_info.config->listens, clients);
 
  distrend_config_free(general_info.config);
src/server/distrend.h
Show inline comments
 
@@ -33,11 +33,8 @@ struct distrend_config
 
  struct options_common *options;
 
  struct distrend_listen *listens; /*< Null terminated array of structs */
 
  char *datadir;
 
};
 

	
 
struct distrend_action
 
{
 
  struct distrend_client *client;
 
  int die;
 
};
 

	
 
#endif
src/server/listen.c
Show inline comments
 
@@ -42,6 +42,8 @@ struct distrend_clientset
 
  int nfds;
 
};
 

	
 
int distrend_client_new(struct distrend_client **client, int sock, enum distrend_client_state state);
 
int distrend_client_free(struct distrend_client *client);
 

	
 
int distrend_listen(struct distrend_config *config, struct distrend_clientset **clients)
 
{
 
@@ -80,21 +82,41 @@ int distrend_listen(struct distrend_conf
 
  return 0;
 
}
 

	
 
int distrend_accept_find_client(fd_set *fdset, struct distrend_client *client)
 
int distrend_handleread(struct distrend_config *config,
 
		    struct distrend_client *client)
 
{
 
  fprintf(stderr, "%s:%d: STUB: I'm supposed to read data from the client\n",
 
	  __FILE__, __LINE__);
 

	
 
  return 0;
 
}
 

	
 
struct distrend_accept_client_proc_data
 
{
 
  if(FD_ISSET(client->sock, fdset))
 
    return FALSE;
 
  fd_set *fdset;
 
  struct distrend_config *config;
 
};
 
int distrend_accept_client_proc(struct distrend_accept_client_proc_data *data,
 
				struct distrend_client *client)
 
{
 
  if(!FD_ISSET(client->sock, data->fdset))
 
    /** continue iteration through the list */
 
    return TRUE;
 

	
 
  fprintf(stderr, "%s:%d: My traversal says that sock %d has data waiting\n",
 
	  __FILE__, __LINE__, client->sock);
 
  distrend_handleread(data->config, client);
 

	
 
  /** continue iteration through the list */
 
  return TRUE;
 
}
 

	
 
int distrend_accept(struct distrend_config *config, struct distrend_clientset *clients, struct distrend_action **action)
 
int distrend_accept(struct distrend_config *config, struct distrend_clientset *clients)
 
{
 
  int tmp;
 
  fd_set readfds;
 
  fd_set writefds;
 

	
 
  struct distrend_client *cli;
 

	
 
  memcpy(&readfds, &clients->readfds, sizeof(fd_set));
 
  memcpy(&writefds, &clients->writefds, sizeof(fd_set));
 

	
 
@@ -107,17 +129,10 @@ int distrend_accept(struct distrend_conf
 
    }
 

	
 
  /**
 
     check if our traversal function found a bit that was set
 
     deal with all sockets that have data waiting
 
   */
 
  if(list_traverse(clients->clients, &readfds, &distrend_accept_find_client, LIST_FRNT | LIST_ALTR) == LIST_OK)
 
    {
 
      cli = (struct distrend_client *)list_curr(clients->clients);
 
      fprintf(stderr, "%s:%d: My traversal says that sock %d has data waiting, which is %s\n",
 
	     __FILE__, __LINE__,
 
	     cli->sock, FD_ISSET(cli->sock, &readfds) ? "true" : "false");
 
      fprintf(stderr, "stub\n");
 
      return 1;
 
    }
 
  list_traverse(clients->clients, &readfds, (list_traverse_func_t)&distrend_accept_client_proc, LIST_FRNT | LIST_ALTR);
 

	
 

	
 
  return 0;
 
}
 
@@ -131,7 +146,32 @@ int distrend_unlisten(struct distrend_li
 
/**
 
   This is probably just NOT a placeholder for remotio
 
*/
 
void remotio_send_to_client()
 
void remotio_send_to_client(struct distrend_client *client, const char *msg, size_t len)
 
{
 
    fprintf(stderr, "%s:%d: STUB I should queue data for writing to a client\n", __FILE__, __LINE__);
 
}
 

	
 
int distrend_client_new(struct distrend_client **client, int sock, enum distrend_client_state state)
 
{
 
  *client = malloc(sizeof(struct distrend_client));
 
  if(!*client)
 
{
 
  fprintf(stderr, "%s:%d: I am futile! And I'm happy because of it :-D\n", __FILE__, __LINE__);
 
      fprintf(stderr, "OOM\n");
 
      return 1;
 
    }
 
  (*client)->sock = sock;
 
  (*client)->state = state;
 
  (*client)->inmsgs = list_init();
 
  (*client)->outmsgs = list_init();
 

	
 
  return 0;
 
}
 

	
 
int distrend_client_free(struct distrend_client *client)
 
{
 
  list_free(client->inmsgs, (void *)LIST_DEALLOC);
 
  list_free(client->outmsgs, (void *)LIST_DEALLOC);
 

	
 
  fprintf(stderr, "%s:%d: stub!", __FILE__, __LINE__);
 
  return 1;
 
}
src/server/listen.h
Show inline comments
 
@@ -26,6 +26,15 @@ struct distrend_client;
 

	
 
#include "distrend.h"
 

	
 
#include <list.h>
 

	
 
enum distrend_client_state
 
  {
 
    DISTREND_CLIENT_PREAUTH,
 
    DISTREND_CLIENT_GOODDOGGY,
 
    DISTREND_CLIENT_BADBOY
 
  };
 

	
 
struct distrend_listen
 
{
 
  int port;
 
@@ -35,7 +44,9 @@ struct distrend_listen
 
struct distrend_client
 
{
 
  int sock;
 
  int state;
 
  enum distrend_client_state state;
 
  LIST *inmsgs;
 
  LIST *outmsgs;
 
};
 

	
 

	
 
@@ -54,7 +65,7 @@ int distrend_listen(struct distrend_conf
 
   signals. If you want to cleanly shut down, it's best to register
 
   signal handlers somewhere
 
 */
 
int distrend_accept(struct distrend_config *config, struct distrend_clientset *clients, struct distrend_action **action);
 
int distrend_accept(struct distrend_config *config, struct distrend_clientset *clients);
 

	
 
/**
 
   cleans listening socket. Unnecessary for a working server, currently a stub.
0 comments (0 inline, 0 general)