Skip to content

Commit

Permalink
Starting on the protocol so I can get things moving.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikhil Samith Bysani committed Dec 25, 2008
1 parent aa8121d commit c304c98
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 10 deletions.
8 changes: 2 additions & 6 deletions src/base/bang-com.c
Expand Up @@ -7,6 +7,7 @@
*
*/
#include"bang-com.h"
#include"bang-net.h"
#include"bang-signals.h"
#include"bang-types.h"
#include<poll.h>
Expand Down Expand Up @@ -149,19 +150,14 @@ void* BANG_read_peer_thread(void *self_info) {
pfd.fd = self->socket;
pfd.events = POLLIN | POLLOUT | POLLERR | POLLHUP | POLLNVAL;

char buf[BUFSIZ];
char *buf[BUFSIZ];
int check_read;

while (1) {
if (poll(&pfd,1,-1) != -1) {
check_read = read(self->socket,buf,BUFSIZ);

if (check_read == 0) {
//TODO: the other end hung up, kill self in some thread safe way
//can't just call remove_peer because uhhh that will cancel us
//and we would have the lock and then things would go wrong =/
//need to send a signal --why am I even commenting when I could
//just right this code--
BANG_sigargs args;
args.args = calloc(1,sizeof(int));
*((int*)args.args) = self->peer_id;
Expand Down
2 changes: 1 addition & 1 deletion src/base/bang-net.h
Expand Up @@ -24,7 +24,7 @@ void BANG_set_server_port(char *new_port);
* \param port The port the server should start at.
* \param start_server If true, the server thread is started on init.
*
* \brief Initalizes the net part of the library.
* \brief Initializes the net part of the library.
*/
void BANG_net_init(char *sever_port,char start_server);

Expand Down
60 changes: 57 additions & 3 deletions src/base/bang-types.h
Expand Up @@ -9,6 +9,8 @@
#ifndef __BANG_TYPES_H
#define __BANG_TYPES_H

#define BANG_VERSION .01

///The structure that represents a module for the program.
typedef struct _BANG_module {
///The name of the module.
Expand All @@ -28,7 +30,7 @@ typedef struct _BANG_module {
typedef struct {
///Arguments you want to send to signal handlers.
void *args;
///Lenth of the arguments.
///Length of the arguments.
int length;
} BANG_sigargs;

Expand Down Expand Up @@ -56,11 +58,63 @@ enum BANG_signals {
BANG_PEER_CONNECTED,
BANG_PEER_DISCONNECTED,

///Don't know if we can implment this signals
/**
* Don't know if we can (will) implement this signals
*/
BANG_CLOSE_ALL,

///The number of signals. All new signals should be above this line.
/**
* The number of signals. All new signals should be above this line.
*/
BANG_NUM_SIGS
} BANG_signal;

/**
*
* \page The Protocol
*
* \brief The protocol is specified, like this:
* - First, an unsigned int will be sent specifying what kind of communication it will be
* - Then, everything else will follow
*
* Following are possible unsigned ints to be sent.
*
* Communications currently can be done by this:
* assuming peer1, peer2
*
* peer1: BANG_HELLO
* peer2: BANG_HELLO
*
* ... any number of BANG_DEBUG_MESSAGE
*
* peer2: BANG_BYE
*
*/

enum BANG_headers {
/**
* message:
* -BANG_HELLO (unsigned int)
* -BANG_VERSION (unsigned double)
* -length of name (unsigned int)
* -peer name (char*)
*/
BANG_HELLO,
/**
* message:
* -BANG_DEBUG_MESSAGE (unsigned int)
* -length of message (unsigned int)
* -message (char*)
*/
BANG_DEBUG_MESSAGE,
/**
* message:
* -BANG_BYE (unsigned int)
*/
BANG_BYE,
/**
* Number of headers.*/
BANG_NUM_HEADERS
} BANG_header;

#endif

0 comments on commit c304c98

Please sign in to comment.