Skip to content

Commit

Permalink
Documented args for BANG_MODULE_REQUEST and BANG_MODULE_EXISTS signal…
Browse files Browse the repository at this point in the history
…s, modified read_module_exists to include peer_id in signal. Wrote a very similar method called read_module_request.

git-svn-id: https://subversion.cs.uiuc.edu/svn/bang/eoh2009@125 69d76c3e-0761-0410-948c-9895a8bb34fc
  • Loading branch information
asjacob2 committed Mar 7, 2009
1 parent a228555 commit 2fd4dc6
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
52 changes: 47 additions & 5 deletions src/base/bang-read-thread.c
Expand Up @@ -203,18 +203,59 @@ static char read_module_exists(BANG_peer *self) {
if ((mod_name_length = (unsigned int*) read_message(self,4)) == NULL)
return 0;

void *mod_args;
if ((mod_args = (void*) read_message(self, (*mod_name_length+4))) == NULL)
char *mod_args;
if ((mod_args = (char*) read_message(self, (*mod_name_length+4))) == NULL)
return 0;

// create new buffer to hold peer_id plus module name and version
char *mod_buffer = (char*)malloc(*mod_name_length+4+sizeof(int));

*mod_buffer = *mod_args;

// Set last sizeof(int) bits to peer_id - may not be a good way to do this.
mod_buffer[*mod_name_length+4] = self->peer_id;

BANG_sigargs mod_exists_args;

mod_exists_args.args = mod_args;
mod_exists_args.length = *mod_name_length+4;
mod_exists_args.args = (void*) mod_buffer;
mod_exists_args.length = *mod_name_length+4+sizeof(int);

free(mod_name_length);

BANG_send_signal(BANG_MODULE_EXISTS,&mod_exists_args,1);
free(mod_buffer);
free(mod_args);

return 1;
}

static char read_module_request(BANG_peer *self) {

unsigned int *mod_name_length;
if ((mod_name_length = (unsigned int*) read_message(self,4)) == NULL)
return 0;

char *mod_args;
if ((mod_args = (char*) read_message(self, (*mod_name_length+4))) == NULL)
return 0;

// create new buffer to hold peer_id plus module name and version
char *mod_buffer = (char*)malloc(*mod_name_length+4+sizeof(int));

*mod_buffer = *mod_args;

// Set last sizeof(int) bits to peer_id - may not be a good way to do this.
mod_buffer[*mod_name_length+4] = self->peer_id;

BANG_sigargs mod_exists_args;

mod_exists_args.args = (void*) mod_buffer;
mod_exists_args.length = *mod_name_length+4+sizeof(int);

free(mod_name_length);

BANG_send_signal(BANG_MODULE_REQUEST,&mod_exists_args,1);
free(mod_buffer);
free(mod_args);

return 1;
Expand Down Expand Up @@ -249,7 +290,8 @@ void* BANG_read_peer_thread(void *self_info) {
break;

case BANG_REQUEST_MODULE:
/* TODO: This may be pretty hard to do. */
/* Send signal to request the new module. */
reading = read_module_request(self);
break;

case BANG_SEND_JOB:
Expand Down
8 changes: 7 additions & 1 deletion src/base/bang-types.h
Expand Up @@ -119,7 +119,13 @@ enum BANG_signals {
*/
BANG_RUNNING_MODULE,
/**
* Send request to get new module.
* Client sends a module to peer.
* arg: module_name | '\0' | module version (3 bytes) | peer_id (int)
*/
BANG_MODULE_REQUEST,
/**
* Send request to see if peer has module.
* arg: module_name | '\0' | module version (3 bytes) | peer_id (int)
*/
BANG_MODULE_EXISTS,
/**
Expand Down

0 comments on commit 2fd4dc6

Please sign in to comment.