#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <pthread.h>
#include <semaphore.h>
#include "tuple.h"
Go to the source code of this file.
Data Structures | |
struct | ttuple |
Doubly-linked list of tuples, for efficient insertions and deletions. More... | |
Defines | |
#define | LOGPRINTF(fmt, a...) if (logptr < 8000) { logptr += sprintf(logbuf+logptr, fmt, ##a); } |
#define | LOGTUPLE(s) print_tuple(s); |
#define | MAXNUMTHREADS 100 |
Functions | |
void | add_tuple_to_space (struct tuple *t) |
void | remove_message_from_space (struct ttuple *s) |
void | kill_this_thread (struct context *arg) |
void | handle_get_read (struct context *ctx, struct tuple *s, int remove, int blocking) |
void | handle_dump_space (struct context *ctx) |
void * | client_thread_func (void *varg) |
int | main (int argc, char *argv[]) |
Variables | |
sem_t | log_sem |
ttuple * | first_message = NULL |
ttuple * | last_message = NULL |
context | client_list [MAXNUMTHREADS] |
sem_t | tuple_space_access |
unsigned char | num_blocked = 0 |
sem_t | blocked_sem |
sem_t | new_client_sem |
The tuple server is responsible for remaining stable while clients misbehave, and making sure that client operations are atomic. Client misbehavior can include things like badly-formed requests and dropped network sockets.
Definition in file tuple_server.c.
|
Definition at line 64 of file tuple_server.c. Referenced by client_thread_func, handle_get_read, and kill_this_thread. |
|
Definition at line 67 of file tuple_server.c. Referenced by client_thread_func. |
|
Definition at line 94 of file tuple_server.c. |
|
When we add a tuple to the space, we unblock all the clients who are waiting for tuples, so they can check and see if this is the one they want. Definition at line 134 of file tuple_server.c. References blocked_sem, ttuple::next, num_blocked, ttuple::previous, ttuple::tuple, and tuple_space_access. Referenced by client_thread_func, and handle_get_read. |
|
When a client makes a connection, find out what it wants, and do that operation. Definition at line 346 of file tuple_server.c. References add_tuple_to_space, DUMP, GET, GET_NB, handle_dump_space, handle_get_read, kill_this_thread, LOG, log_sem, LOGPRINTF, LOGTUPLE, PUT, READ, READ_NB, recv_chunk, recv_tuple, context::sock, and context::thr. Referenced by main. |
|
When a client requests a dump of the tuple space, handle that here. Definition at line 272 of file tuple_server.c. References tuple_list::next, ttuple::next, recv_chunk, recv_tuple, send_chunk, send_tuple, tuple_list::tup, ttuple::tuple, tuple_space_access, and tuples_match. Referenced by client_thread_func. |
|
Handle GETs and READs, both blocking and non-blocking. Definition at line 210 of file tuple_server.c. References add_tuple_to_space, blocked_sem, DBGPRINTF, destroy_tuple, log_sem, LOGPRINTF, ttuple::next, num_blocked, remove_message_from_space, send_chunk, send_tuple, context::sock, ttuple::tuple, tuple_space_access, and tuples_match. Referenced by client_thread_func. |
|
Definition at line 196 of file tuple_server.c. References LOGPRINTF, context::sock, and context::thr. Referenced by client_thread_func. |
|
Set up a socket to listen for incoming requests. When one arrives, start a pthread to handle it, and run client_thread_func(). Definition at line 451 of file tuple_server.c. References blocked_sem, client_thread_func, EXIT, log_sem, new_client_sem, context::sock, context::thr, and tuple_space_access. |
|
Tuples are kept in a doubly-linked list, so there's a lot of pointer-hacking here. Definition at line 167 of file tuple_server.c. References ttuple::next, and ttuple::previous. Referenced by handle_get_read. |
|
When threads/clients block, they wait for this semaphore. Definition at line 119 of file tuple_server.c. Referenced by add_tuple_to_space, handle_get_read, and main. |
|
Maintain a list of the clients currently trying to access tuple space. Keep track of a pthread and a socket for each one. Definition at line 100 of file tuple_server.c. |
|
Pointer to the first tuple in tuple space. When there is a GET or READ operation, the search begins with the first tuple. Definition at line 84 of file tuple_server.c. |
|
Pointer to the last tuple in tuple space. When there is a PUT operation, the tuple is put at the end of the list. Definition at line 90 of file tuple_server.c. |
|
Definition at line 62 of file tuple_server.c. Referenced by client_thread_func, handle_get_read, and main. |
|
When a client makes a connection, this semaphore protects client_list. Definition at line 125 of file tuple_server.c. Referenced by main. |
|
Keep track of how many threads/clients are currently blocked, so that we can increment blocked_sem by the proper amount. Definition at line 114 of file tuple_server.c. Referenced by add_tuple_to_space, and handle_get_read. |
|
Semaphore to make sure that all tuple operations are atomic. Each client finishes his operation before the next guy is allowed to begin. Definition at line 108 of file tuple_server.c. Referenced by add_tuple_to_space, handle_dump_space, handle_get_read, and main. |