Changeset 35

Show
Ignore:
Timestamp:
05/29/08 22:10:19 (6 months ago)
Author:
jtang
Message:

Ran 'make indent' on all code.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libsipc/include/sipc/sipc.h

    r24 r35  
    5353 *      the sipc_t struct.  Caller must call sipc_close to free the memory. 
    5454 */ 
    55 sipc_t *sipc_open(const char *key, int role, int ipc_type, size_t size);  
     55sipc_t *sipc_open(const char *key, int role, int ipc_type, size_t size); 
    5656 
    5757/* Free the sipc struct and its contents */ 
    58 void sipc_close(sipc_t *sipc); 
     58void sipc_close(sipc_t * sipc); 
    5959 
    6060/* Called by a helper application to destroy an IPC resource. 
     
    6565 * This can only be called if sender was specified when sipc_init was called.  
    6666 * returns 0 on success, <0 on failure */ 
    67 int sipc_send_data(sipc_t *sipc, int msg_len); 
     67int sipc_send_data(sipc_t * sipc, int msg_len); 
    6868 
    6969/* Blocking call to recieve data. Data will be allocated and filled and 
    7070 * len will be set to the length. Returns 0 on success, <0 on failure */ 
    71 int sipc_recv_data(sipc_t *sipc, char **data, int *len); 
     71int sipc_recv_data(sipc_t * sipc, char **data, int *len); 
    7272 
    7373/* Returns a pointer to the data contained within the IPC resource */ 
    74 char *sipc_get_data_ptr(sipc_t *sipc); 
     74char *sipc_get_data_ptr(sipc_t * sipc); 
    7575 
    7676/* Prints an error message, accepts printf format string */ 
    77 void sipc_error(sipc_t *sipc, const char *fmt, ...) 
    78         __attribute__ ((format (printf, 2, 3))); 
     77void sipc_error(sipc_t * sipc, const char *fmt, ...) 
     78        __attribute__ ((format(printf, 2, 3))); 
    7979 
    8080/* Some IPC types unfortunatly need limited access to underlying mechanism */ 
     
    8282 
    8383/* Receiver calls this when it is done receiving a message in shared memory */ 
    84 int sipc_shm_recv_done(sipc_t *sipc); 
     84int sipc_shm_recv_done(sipc_t * sipc); 
    8585 
    8686#endif 
  • trunk/libsipc/src/mqueue_internal.c

    r32 r35  
    4141        int msqid; 
    4242 
    43         msqid = msgget(key, MQ_PERMS|IPC_CREAT|IPC_EXCL); 
     43        msqid = msgget(key, MQ_PERMS | IPC_CREAT | IPC_EXCL); 
    4444        if (msqid < 0) 
    4545                fprintf(stderr, "msgget: %s\n", strerror(errno)); 
  • trunk/libsipc/src/mqueue_internal.h

    r1 r35  
    1919*/ 
    2020 
    21  
    2221#ifndef _MQUEUE_INTERNAL_H_ 
    2322#define _MQUEUE_INTERNAL_H_ 
  • trunk/libsipc/src/shm_internal.c

    r30 r35  
    3131 
    3232/* Receive NOP messages, which will unblock the sender */ 
    33 int sipc_shm_recv_done(sipc_t *sipc) 
     33int sipc_shm_recv_done(sipc_t * sipc) 
    3434{ 
    3535        if (!sipc) 
     
    4747{ 
    4848        int shmid = 0; 
    49          
     49 
    5050        /* Get the segment's ID */ 
    5151        shmid = shmget(sipc_key, 0, 0); 
     
    5454                return; 
    5555        } 
    56         
     56 
    5757        /* Mark the segment for removal; this will actually 
    5858           destroy the segment only if the sender and receiver have detached */ 
    59         if (shmctl(shmid, IPC_RMID, NULL) < 0)  
     59        if (shmctl(shmid, IPC_RMID, NULL) < 0) 
    6060                fprintf(stderr, "shmctl: %s\n", strerror(errno)); 
    61          
     61 
    6262} 
  • trunk/libsipc/src/shm_internal.h

    r1 r35  
    1919*/ 
    2020 
    21  
    2221#ifndef _SHM_INTERNAL_H_ 
    2322#define _SHM_INTERNAL_H_ 
  • trunk/libsipc/src/sipc.c

    r24 r35  
    2929#include "sipc_internal.h" 
    3030 
    31 int (*sipc_init_f[SIPC_NUM_TYPES]) (sipc_t *sipc) = { 
    32         sipc_shm_init, 
    33         sipc_mqueue_init, 
    34 }; 
     31int (*sipc_init_f[SIPC_NUM_TYPES]) (sipc_t * sipc) = { 
     32sipc_shm_init, sipc_mqueue_init,}; 
    3533 
    3634sipc_t *sipc_open(const char *key, int role, int ipc_type, size_t len) 
     
    5957 
    6058        /* call backend specific init to fill in function table */ 
    61         if (sipc_init_f[ipc_type](new_sipc)) 
     59        if (sipc_init_f[ipc_type] (new_sipc)) 
    6260                goto err; 
    6361 
     
    8179 
    8280        return new_sipc; 
    83 err: 
     81      err: 
    8482        free(new_sipc); 
    8583        return NULL; 
    8684} 
    8785 
    88 void sipc_close(sipc_t *sipc) 
     86void sipc_close(sipc_t * sipc) 
    8987{ 
    9088        if (!sipc) 
    9189                return; 
    9290 
    93         sipc->funcs->sipc_detach(sipc); 
     91       sipc->funcs->sipc_detach(sipc); 
    9492        free(sipc); 
    9593} 
     
    118116} 
    119117 
    120 char *sipc_get_data_ptr(sipc_t *sipc) 
     118char *sipc_get_data_ptr(sipc_t * sipc) 
    121119{ 
    122120        if (!sipc) 
     
    126124} 
    127125 
    128 int sipc_send_data(sipc_t *sipc, int msg_len) 
     126int sipc_send_data(sipc_t * sipc, int msg_len) 
    129127{ 
    130128        if (!sipc) 
     
    134132} 
    135133 
    136 int sipc_recv_data(sipc_t *sipc, char **data, int *len) 
     134int sipc_recv_data(sipc_t * sipc, char **data, int *len) 
    137135{ 
    138136        if (!sipc) 
     
    142140} 
    143141 
    144 void sipc_error(sipc_t *sipc, const char *fmt, ...) 
     142void sipc_error(sipc_t * sipc, const char *fmt, ...) 
    145143{ 
    146144        if (!sipc) 
  • trunk/libsipc/src/sipc_internal.h

    r21 r35  
    3838 
    3939/* Creation functions */ 
    40 int sipc_mqueue_create(sipc_t *sipc); 
    41 int sipc_shm_create(sipc_t *sipc); 
     40int sipc_mqueue_create(sipc_t * sipc); 
     41int sipc_shm_create(sipc_t * sipc); 
    4242int mqueue_create(key_t key); 
    4343 
    4444/* Attach functions */ 
    45 int sipc_mqueue_attach(sipc_t *sipc); 
    46 int sipc_shm_attach(sipc_t *sipc); 
     45int sipc_mqueue_attach(sipc_t * sipc); 
     46int sipc_shm_attach(sipc_t * sipc); 
    4747 
    4848/* Detach functions */ 
    49 void sipc_mqueue_detach(sipc_t *sipc); 
    50 void sipc_shm_detach(sipc_t *sipc); 
     49void sipc_mqueue_detach(sipc_t * sipc); 
     50void sipc_shm_detach(sipc_t * sipc); 
    5151 
    5252/* Destruction functions */ 
     
    5555 
    5656/* Initialization functions */ 
    57 int sipc_mqueue_init(sipc_t *sipc); 
    58 int sipc_shm_init(sipc_t *sipc); 
     57int sipc_mqueue_init(sipc_t * sipc); 
     58int sipc_shm_init(sipc_t * sipc); 
    5959 
    6060/* all ipc backends must implement all of these functions */ 
    61 struct sipc_func_table { 
    62         int (*sipc_create) (sipc_t *sipc); 
    63         int (*sipc_attach) (sipc_t *sipc); 
    64         char *(*sipc_get_data_ptr) (sipc_t *sipc); 
    65         int (*sipc_send_data) (sipc_t *sipc, int msg_len); 
    66         int (*sipc_recv_data) (sipc_t *sipc, char **data, int *len); 
    67         void (*sipc_detach) (sipc_t *sipc); 
     61struct sipc_func_table 
     62
     63        int (*sipc_create) (sipc_t * sipc); 
     64        int (*sipc_attach) (sipc_t * sipc); 
     65        char *(*sipc_get_data_ptr) (sipc_t * sipc); 
     66        int (*sipc_send_data) (sipc_t * sipc, int msg_len); 
     67        int (*sipc_recv_data) (sipc_t * sipc, char **data, int *len); 
     68        void (*sipc_detach) (sipc_t * sipc); 
    6869        void (*_sipc_error) (const char *fmt, va_list ap); 
    6970}; 
    7071 
    71 struct sipc {  
     72struct sipc 
     73
    7274        key_t key; 
    7375        int ipc_type; 
    7476        int role; 
    75         union { 
    76                 int fd; /* file desciptor for socket connections */ 
    77                 struct shm { /* shm data */ 
    78                         int shmid; /* ID of segment */                   
    79                         int msqid; /* notify channel */ 
     77        union 
     78        { 
     79                int fd;                /* file desciptor for socket connections */ 
     80                struct shm 
     81                {                      /* shm data */ 
     82                        int shmid;     /* ID of segment */ 
     83                        int msqid;     /* notify channel */ 
    8084                        /* sipc_t *mqueue; handle to notify channel */ 
    8185                } s; 
    82                 int msqid; /* message queue */ 
     86                int msqid;            /* message queue */ 
    8387        }; 
    8488 
    8589        char *data; 
    86         size_t len;     
    87         size_t msg_len; /* Length in bytes of the next message */ 
    88         size_t copied;         /* Number of bytes xmitted so far */ 
     90        size_t len; 
     91        size_t msg_len;                      /* Length in bytes of the next message */ 
     92        size_t copied;                /* Number of bytes xmitted so far */ 
    8993        struct sipc_func_table *funcs; 
    90 };      
     94}; 
  • trunk/libsipc/src/sipc_mqueue.c

    r34 r35  
    5050 
    5151/* Forward decls */ 
    52 static int get_max_msg(sipc_t *sipc); 
    53 static int mqueue_send_msg_len(sipc_t *sipc, int msg_len); 
    54 static int mqueue_send_end_xmit(sipc_t *sipc); 
    55 static char *split_data(sipc_t *sipc, size_t packet_sz); 
     52static int get_max_msg(sipc_t * sipc); 
     53static int mqueue_send_msg_len(sipc_t * sipc, int msg_len); 
     54static int mqueue_send_end_xmit(sipc_t * sipc); 
     55static char *split_data(sipc_t * sipc, size_t packet_sz); 
    5656static int is_msg_len(struct msgbuf *mbuf); 
    5757static int is_end_xmit(struct msgbuf *mbuf); 
    58 static int msg_done(sipc_t *sipc); 
     58static int msg_done(sipc_t * sipc); 
    5959static size_t next_packet_sz(int recv, int max_packet_sz, int msg_len); 
    6060static size_t next_alloc_sz(int recv, int recv_sz, int max_packet_sz, int msg_len); 
    6161 
    62 int sipc_mqueue_init(sipc_t *sipc) 
     62int sipc_mqueue_init(sipc_t * sipc) 
    6363{ 
    6464        if (!sipc) 
     
    7979 * This function should only be called by a helper application 
    8080 * and not by the sender or reciever. */ 
    81 int sipc_mqueue_create(sipc_t *sipc) 
     81int sipc_mqueue_create(sipc_t * sipc) 
    8282{ 
    8383        int msqid; 
    8484 
    8585        msqid = mqueue_create(sipc->key); 
    86         if (msqid < 0)
     86        if (msqid < 0)
    8787                fprintf(stderr, "msgget: %s\n", strerror(errno)); 
    8888                return -1; 
     
    9393} 
    9494 
    95 void sipc_mqueue_detach(sipc_t *sipc) 
     95void sipc_mqueue_detach(sipc_t * sipc) 
    9696{ 
    9797        free(sipc->data); 
     
    100100 
    101101/* Attach to an existing message queue. */ 
    102 int sipc_mqueue_attach(sipc_t *sipc) 
     102int sipc_mqueue_attach(sipc_t * sipc) 
    103103{ 
    104104        /* Allocate data member */ 
    105105        sipc->data = calloc(1, sipc->len); 
    106106        if (!sipc->data) { 
    107              sipc_error(sipc, "Out of memory\n"); 
    108              return -1; 
     107               sipc_error(sipc, "Out of memory\n"); 
     108               return -1; 
    109109        } 
    110110 
     
    120120} 
    121121 
    122 char *sipc_mqueue_get_data_ptr(sipc_t *sipc) 
     122char *sipc_mqueue_get_data_ptr(sipc_t * sipc) 
    123123{ 
    124124        return sipc->data; 
     
    127127/* Sends a message to the queue. 
    128128 * Returns 0 on success, -1 on error */ 
    129 int sipc_mqueue_send_data(sipc_t *sipc, int msg_len) 
     129int sipc_mqueue_send_data(sipc_t * sipc, int msg_len) 
    130130{ 
    131131        int max_packet_sz = SIPC_MQUEUE_MSG_SZ - sizeof(struct msgbuf); 
     
    137137                goto err; 
    138138 
    139         mbuf = (struct msgbuf *) calloc(1, SIPC_MQUEUE_MSG_SZ); 
     139        mbuf = (struct msgbuf *)calloc(1, SIPC_MQUEUE_MSG_SZ); 
    140140        if (!mbuf) { 
    141141                sipc_error(sipc, "%s\n", "Out of memory"); 
     
    146146        mqueue_send_msg_len(sipc, msg_len); 
    147147 
    148         sipc->copied = 0; /* Reset copied data counter */ 
     148        sipc->copied = 0;            /* Reset copied data counter */ 
    149149        do { 
    150150                packet_sz = next_packet_sz(sipc->copied, max_packet_sz, msg_len); 
     
    173173        return 0; 
    174174 
    175 err: 
     175      err: 
    176176        free(packet); 
    177177        free(mbuf); 
     
    180180} 
    181181 
    182 int sipc_mqueue_recv_data(sipc_t *sipc, char **data, int *len) 
     182int sipc_mqueue_recv_data(sipc_t * sipc, char **data, int *len) 
    183183{ 
    184184        int retv = -1, alloc_sz = 0, idx = 0, recv_sz; 
     
    199199        } 
    200200 
    201         *data = NULL;   /* Pointer to a buffer created here */ 
    202         idx = 0;        /* Current index into the buffer */ 
    203         *len = 0;       /* Bytes received so far */ 
     201        *data = NULL;                 /* Pointer to a buffer created here */ 
     202        idx = 0;                      /* Current index into the buffer */ 
     203        *len = 0;                     /* Bytes received so far */ 
    204204 
    205205        /* Receive and validate the length of message marker */ 
     
    220220                        if (sipc->msg_len > sipc->len) { 
    221221                                sipc_error(sipc, "libsipc: cannot receive buffer of size %zd, can only receive %zd\n", 
    222                                         sipc->msg_len, sipc->len); 
     222                                           sipc->msg_len, sipc->len); 
    223223                                goto err; 
    224224                        } 
     
    240240        while (!is_end_xmit(mbuf)) { 
    241241                /* If this isn't the last packet in the message, 
    242                 * resize to +1 message */ 
     242                * resize to +1 message */ 
    243243                alloc_sz += next_alloc_sz(*len, recv_sz, msgtxt_sz, sipc->msg_len); 
    244244 
     
    253253 
    254254                /* memset(*data+idx, 0x0, recv_sz); */ 
    255                 memcpy(*data+idx, mbuf->mtext, recv_sz); 
     255                memcpy(*data + idx, mbuf->mtext, recv_sz); 
    256256                idx += recv_sz; 
    257257 
     
    270270 
    271271        retv = 0; 
    272 err: 
     272      err: 
    273273        sipc->msg_len = SIPC_MSGLEN_NOT_SET;    /* Unset message length */ 
    274274        free(mbuf); 
     
    283283/* Gets the maximum allowed size of a message in a message queue. 
    284284 * Returns the maximum allowed size of a message, -1 on error */ 
    285 static int get_max_msg(sipc_t *sipc) 
     285static int get_max_msg(sipc_t * sipc) 
    286286{ 
    287287        FILE *f; 
     
    298298        } 
    299299        if (fclose(f) == EOF) 
    300                 sipc_error(sipc, "fclose: %s\n", strerror(errno)); 
     300               sipc_error(sipc, "fclose: %s\n", strerror(errno)); 
    301301 
    302302        return atoi(buf); 
     
    304304 
    305305/* Send end of transmission marker */ 
    306 static int mqueue_send_end_xmit(sipc_t *sipc) 
     306static int mqueue_send_end_xmit(sipc_t * sipc) 
    307307{ 
    308308        struct msgbuf mbuf; 
     
    322322{ 
    323323        int i = 1; 
    324         while(x) { 
     324        while (x) { 
    325325                i++; 
    326326                x /= 10; 
     
    329329} 
    330330 
    331 static int mqueue_send_msg_len(sipc_t *sipc, int len) 
    332 { 
    333         struct msgbuf *mbuf; 
     331static int mqueue_send_msg_len(sipc_t * sipc, int len) 
     332{ 
     333       struct msgbuf *mbuf; 
    334334 
    335335        if (len < 0) 
     
    339339        mbuf = calloc(1, sizeof(struct msgbuf) + qlog(len)); 
    340340        if (!mbuf) { 
    341                 sipc_error(sipc,"Out of memory!\n"); 
     341                sipc_error(sipc, "Out of memory!\n"); 
    342342                return -1; 
    343343        } 
     
    376376/* Returns 1 if the message has been completely fragmented, 
    377377 * 0 otherwise. */ 
    378 static int msg_done(sipc_t *sipc) 
     378static int msg_done(sipc_t * sipc) 
    379379{ 
    380380        return sipc->copied >= sipc->msg_len ? 1 : 0; 
    381381} 
    382  
    383382 
    384383/* Splits data in sipc into a chunk the size of the maximum 
     
    386385 * This function allocates space for the fragmented piece of data. 
    387386 * The caller is responsible for freeign this memory. */ 
    388 static char *split_data(sipc_t *sipc, size_t packet_sz) 
     387static char *split_data(sipc_t * sipc, size_t packet_sz) 
    389388{ 
    390389        size_t remaining = sipc->msg_len - sipc->copied; 
     
    394393                return NULL; 
    395394 
    396         memcpy(packet, (sipc->data)+(sipc->copied), len); 
     395        memcpy(packet, (sipc->data) + (sipc->copied), len); 
    397396        sipc->copied += len; 
    398397 
  • trunk/libsipc/src/sipc_mqueue.h

    r21 r35  
    2828#define MQ_NOBLOCK 0 
    2929 
    30 int sipc_mqueue_init(sipc_t *sipc); 
    31 int sipc_mqueue_connect(sipc_t *sipc); 
    32 void sipc_mqueue_disconnect(sipc_t *sipc); 
    33 char *sipc_mqueue_get_data_ptr(sipc_t *sipc); 
    34 int sipc_mqueue_send_data(sipc_t *sipc, int msg_len); 
    35 int sipc_mqueue_recv_data(sipc_t *sipc, char **data, int *len); 
    36 int sipc_mqueue_end_xmit(sipc_t *sipc); 
    37 void sipc_mqueue_destroy_handle(sipc_t *sipc); 
     30int sipc_mqueue_init(sipc_t * sipc); 
     31int sipc_mqueue_connect(sipc_t * sipc); 
     32void sipc_mqueue_disconnect(sipc_t * sipc); 
     33char *sipc_mqueue_get_data_ptr(sipc_t * sipc); 
     34int sipc_mqueue_send_data(sipc_t * sipc, int msg_len); 
     35int sipc_mqueue_recv_data(sipc_t * sipc, char **data, int *len); 
     36int sipc_mqueue_end_xmit(sipc_t * sipc); 
     37void sipc_mqueue_destroy_handle(sipc_t * sipc); 
    3838void sipc_mqueue_error(const char *fmt, va_list ap); 
    3939 
  • trunk/libsipc/src/sipc_shm.c

    r34 r35  
    4343        .sipc_create = sipc_shm_create, 
    4444        .sipc_attach = sipc_shm_attach, 
    45         .sipc_get_data_ptr = sipc_shm_get_data_ptr,  
     45        .sipc_get_data_ptr = sipc_shm_get_data_ptr, 
    4646        .sipc_send_data = sipc_shm_send_data, 
    47         .sipc_recv_data = sipc_shm_recv_data,        
     47        .sipc_recv_data = sipc_shm_recv_data, 
    4848        .sipc_detach = sipc_shm_detach, 
    4949        ._sipc_error = sipc_shm_error 
    5050}; 
    5151 
    52 int sipc_shm_init(sipc_t *sipc) 
    53 {       
    54         if (!sipc) 
    55                 return -1; 
    56  
    57       sipc->funcs = &shm_funcs; 
     52int sipc_shm_init(sipc_t * sipc) 
     53{ 
     54        if (!sipc) 
     55                return -1; 
     56 
     57      sipc->funcs = &shm_funcs; 
    5858        sipc->data = NULL; 
    59          
    60         return 0; 
    61 } 
    62  
    63 int sipc_shm_create(sipc_t *sipc) 
     59 
     60        return 0; 
     61} 
     62 
     63int sipc_shm_create(sipc_t * sipc) 
    6464{ 
    6565        if (!sipc) 
     
    7979 
    8080        /* Set capacity of side channel to 1 message */ 
    81         if (sipc->role == SIPC_SENDER && 
    82             mqueue_set_capacity(sipc->s.msqid, sizeof(struct msgbuf)) < 0)  
    83                 goto err; 
    84  
    85         return 0; 
    86          
    87 err: 
    88         if (sipc->s.shmid != (key_t)-1) 
     81        if (sipc->role == SIPC_SENDER && mqueue_set_capacity(sipc->s.msqid, sizeof(struct msgbuf)) < 0) 
     82                goto err; 
     83 
     84        return 0; 
     85 
     86      err: 
     87        if (sipc->s.shmid != (key_t) - 1) 
    8988                shmctl(sipc->s.shmid, IPC_RMID, NULL); 
    9089        return -1; 
    9190} 
    9291 
    93 int sipc_shm_attach(sipc_t *sipc) 
     92int sipc_shm_attach(sipc_t * sipc) 
    9493{ 
    9594        int flags = 0; 
     
    105104                goto err; 
    106105        } 
    107          
     106 
    108107        /* Attach to the shm segment */ 
    109108        flags = sipc->role == SIPC_SENDER ? 0 : SHM_RDONLY; 
    110         if ((sipc->data = shmat(sipc->s.shmid, NULL, flags)) == (char *)-1) { 
    111                 sipc_error(sipc, "shmat: %s\n", strerror(errno)); 
    112                 goto err; 
    113         }                        
     109       if ((sipc->data = shmat(sipc->s.shmid, NULL, flags)) == (char *)-1) { 
     110               sipc_error(sipc, "shmat: %s\n", strerror(errno)); 
     111                goto err; 
     112        } 
    114113 
    115114        /* Connect side channel */ 
     
    121120 
    122121        return 0; 
    123 err: 
     122      err: 
    124123        sipc_shm_detach(sipc); 
    125124        return -1; 
    126125} 
    127126 
    128 void sipc_shm_detach(sipc_t *sipc) 
     127void sipc_shm_detach(sipc_t * sipc) 
    129128{ 
    130129        if (!sipc) 
    131130                return; 
    132          
     131 
    133132        /* If we're the receiver, disconnect side channel */ 
    134         if (sipc->role == SIPC_RECEIVER)        
     133        if (sipc->role == SIPC_RECEIVER) 
    135134                mqueue_disconnect(sipc->s.msqid); 
    136              
     135 
    137136        /* Detach shm segment */ 
    138137        if (sipc->data) { 
    139                 if (shmdt(sipc->data) < 0)  
     138                if (shmdt(sipc->data) < 0) 
    140139                        sipc_error(sipc, "shmdt: %s\n", strerror(errno)); 
    141140        } 
     
    144143void sipc_shm_error(const char *fmt, va_list ap) 
    145144{ 
    146         vfprintf(stderr, fmt, ap);        
    147 } 
    148  
    149 char *sipc_shm_get_data_ptr(sipc_t *sipc) 
     145        vfprintf(stderr, fmt, ap); 
     146} 
     147 
     148char *sipc_shm_get_data_ptr(sipc_t * sipc) 
    150149{ 
    151150        return sipc->data; 
     
    153152 
    154153/* Sends a DATA_READY marker, followed by 2 NOP markers */ 
    155 int sipc_shm_send_data(sipc_t *sipc, int msg_len) 
    156 {     
     154int sipc_shm_send_data(sipc_t * sipc, int msg_len) 
     155{ 
    157156        if (!sipc) 
    158157                return -1; 
    159158 
    160159        /* Send a DATA_READY marker */ 
    161         if (mqueue_send_msg_type(sipc->s.msqid, SIPC_DATA_READY, MQ_BLOCK) < 0) { 
     160       if (mqueue_send_msg_type(sipc->s.msqid, SIPC_DATA_READY, MQ_BLOCK) < 0) { 
    162161                sipc_error(sipc, "Could not send DATA_READY marker\n"); 
    163162                return -1; 
    164163        } 
    165                  
     164 
    166165        /* Send a NULL marker; this should block at first */ 
    167166        if (mqueue_send_msg_type(sipc->s.msqid, SIPC_NOP, MQ_BLOCK) < 0) { 
    168167                sipc_error(sipc, "Could not send NOP marker\n"); 
    169168                return -1; 
    170         }  
     169        } 
    171170 
    172171        /* Send another NULL marker */ 
    173172        if (mqueue_send_msg_type(sipc->s.msqid, SIPC_NOP, MQ_BLOCK) < 0) { 
    174              sipc_error(sipc, "Could not send NOP marker\n"); 
    175              return -1; 
    176         }  
    177                  
     173               sipc_error(sipc, "Could not send NOP marker\n"); 
     174               return -1; 
     175        } 
     176 
    178177        return 0; 
    179178} 
     
    183182 * This function will block if the DATA_READY marker is not 
    184183 * present on the queue. */ 
    185 int sipc_shm_recv_data(sipc_t *sipc, char **data, int *len) 
    186 { 
    187         int mtype = 0; 
    188          
     184int sipc_shm_recv_data(sipc_t * sipc, char **data, int *len) 
     185{ 
     186       int mtype = 0; 
     187 
    189188        if (!sipc || !data || !len) 
    190189                return -1; 
    191190 
    192191        /* Get a message from the side channel; exit when it's END_XMIT */ 
    193         mtype = mqueue_get_msg_type(sipc->s.msqid, SIPC_ANY, MQ_BLOCK);         
     192        mtype = mqueue_get_msg_type(sipc->s.msqid, SIPC_ANY, MQ_BLOCK); 
    194193        if (mtype == SIPC_DATA_READY) { 
    195194                /* It is now OK to read shared memory */ 
     
    199198        } else { 
    200199                sipc_error(sipc, "Received a message of unknown type\n"); 
    201                 return -1;       
    202         }                        
    203          
    204         return 0; 
    205 
    206           
     200                return -1; 
     201        } 
     202 
     203        return 0; 
     204
  • trunk/libsipc/src/sipc_shm.h

    r21 r35  
    2525#include <stdarg.h> 
    2626 
    27 int sipc_shm_init(sipc_t *sipc); 
    28 int sipc_shm_connect(sipc_t *sipc); 
    29 void sipc_shm_disconnect(sipc_t *sipc); 
    30 char *sipc_shm_get_data_ptr(sipc_t *sipc); 
    31 int sipc_shm_send_data(sipc_t *sipc, int msg_len); 
    32 int sipc_shm_recv_data(sipc_t *sipc, char **data, int *len); 
    33 int sipc_shm_end_xmit(sipc_t *sipc); 
    34 void sipc_shm_destroy_handle(sipc_t *sipc); 
     27int sipc_shm_init(sipc_t * sipc); 
     28int sipc_shm_connect(sipc_t * sipc); 
     29void sipc_shm_disconnect(sipc_t * sipc); 
     30char *sipc_shm_get_data_ptr(sipc_t * sipc); 
     31int sipc_shm_send_data(sipc_t * sipc, int msg_len); 
     32int sipc_shm_recv_data(sipc_t * sipc, char **data, int *len); 
     33int sipc_shm_end_xmit(sipc_t * sipc); 
     34void sipc_shm_destroy_handle(sipc_t * sipc); 
    3535void sipc_shm_error(const char *fmt, va_list ap); 
    3636 
  • trunk/libsipc/tests/ipc_creator.c

    r21 r35  
    3333                return -1; 
    3434        } 
    35                          
     35 
    3636        sipc = sipc_open(argv[1], SIPC_CREATOR, atoi(argv[2]), DATA_LEN); 
    3737        if (sipc == NULL) { 
  • trunk/libsipc/tests/mqueue.c

    r34 r35  
    4141static sipc_t *writer_ipc; 
    4242static sipc_t *reader_ipc; 
    43 static int send_end_xmit(sipc_t *ipc); 
     43static int send_end_xmit(sipc_t * ipc); 
    4444static void do_parent(void); 
    4545static void do_child(void); 
     
    7575 
    7676        /* Open IPCs */ 
    77         writer_ipc = 
    78             sipc_open(SIPC_MQ_KEY, SIPC_SENDER, SIPC_SYSV_MQUEUES, DATA_LEN); 
     77        writer_ipc = sipc_open(SIPC_MQ_KEY, SIPC_SENDER, SIPC_SYSV_MQUEUES, DATA_LEN); 
    7978        if (writer_ipc == NULL) { 
    8079                fprintf(stderr, "Unable to initialize IPC resource\n"); 
    8180                return -1; 
    8281        } 
    83         reader_ipc = 
    84             sipc_open(SIPC_MQ_KEY, SIPC_RECEIVER, SIPC_SYSV_MQUEUES, DATA_LEN); 
     82        reader_ipc = sipc_open(SIPC_MQ_KEY, SIPC_RECEIVER, SIPC_SYSV_MQUEUES, DATA_LEN); 
    8583        if (reader_ipc == NULL) { 
    8684                fprintf(stderr, "Error initializing IPC resource\n"); 
     
    127125} 
    128126 
    129 static void test_unforked_mqueue(void) { 
     127static void test_unforked_mqueue(void) 
     128
    130129        static char message[] = "HELLO,"; 
    131130        size_t message_len = sizeof(message); 
     
    166165 
    167166CU_TestInfo mqueue_tests[] = { 
    168         {"unforked mqueue", test_unforked_mqueue}, 
    169         {"forked mqueue", test_mqueue} 
    170         , 
    171         CU_TEST_INFO_NULL 
     167        {"unforked mqueue", test_unforked_mqueue} 
     168        , 
     169        {"forked mqueue", test_mqueue} 
     170        , 
     171        CU_TEST_INFO_NULL 
    172172}; 
    173173 
     
    219219} 
    220220 
    221 static int send_end_xmit(sipc_t *ipc) 
     221static int send_end_xmit(sipc_t * ipc) 
    222222{ 
    223223        char *data = sipc_get_data_ptr(ipc); 
     
    228228 
    229229        bzero(data, DATA_LEN); 
    230         strncpy(data, XMIT_END, DATA_LEN-1); 
     230        strncpy(data, XMIT_END, DATA_LEN - 1); 
    231231        if (sipc_send_data(ipc, DATA_LEN) < 0) { 
    232232                sipc_error(ipc, "Unable to send end of transmission marker\n"); 
  • trunk/libsipc/tests/shm.c

    r33 r35  
    4646static void do_binary_child(void); 
    4747static void do_binary_parent(void); 
    48 static void send_end_xmit(sipc_t *sipc); 
     48static void send_end_xmit(sipc_t * sipc); 
    4949static int verify_data(char *filename, char *recv_data); 
    5050static inline int END_XMIT(char *data); 
     
    8080 
    8181        /* Open IPCs */ 
    82         writer_ipc = 
    83             sipc_open(SIPC_SHM_KEY, SIPC_SENDER, SIPC_SYSV_SHM, DATA_LEN); 
     82        writer_ipc = sipc_open(SIPC_SHM_KEY, SIPC_SENDER, SIPC_SYSV_SHM, DATA_LEN); 
    8483        if (writer_ipc == NULL) { 
    8584                fprintf(stderr, "Could not initialize IPC resource\n"); 
    8685                return -1; 
    8786        } 
    88         reader_ipc = 
    89             sipc_open(SIPC_SHM_KEY, SIPC_RECEIVER, SIPC_SYSV_SHM, DATA_LEN); 
     87        reader_ipc = sipc_open(SIPC_SHM_KEY, SIPC_RECEIVER, SIPC_SYSV_SHM, DATA_LEN); 
    9088        if (reader_ipc == NULL) { 
    9189                fprintf(stderr, "Could not initialize IPC resource\n"); 
     
    131129} 
    132130 
    133 static void test_unforked_shm(void) { 
     131static void test_unforked_shm(void) 
     132
    134133        static char message[] = "HELLO,"; 
    135134        size_t message_len = sizeof(message); 
     
    194193 
    195194CU_TestInfo shm_tests[] = { 
    196         {"unforked shm", test_unforked_shm}, 
    197         {"forked shm", test_shm}, 
    198         {"binary shm", test_binary_shm}, 
     195        {"unforked shm", test_unforked_shm} 
     196        , 
     197        {"forked shm", test_shm} 
     198        , 
     199        {"binary shm", test_binary_shm} 
     200        , 
    199201        CU_TEST_INFO_NULL 
    200202}; 
     
    213215        } 
    214216 
    215         if ((ifile = fopen(IN_FILE, "r")) == NULL) { 
     217       if ((ifile = fopen(IN_FILE, "r")) == NULL) { 
    216218                sipc_error(writer_ipc, "fopen: %s\n", strerror(errno)); 
    217219                return; 
     
    219221        /* Read DATA_LEN bytes from file */ 
    220222        bzero(shm_data, DATA_LEN); 
    221         if ((rbytes = fread(shm_data, sizeof(char), DATA_LEN-1, ifile)) < 0) { 
     223        if ((rbytes = fread(shm_data, sizeof(char), DATA_LEN - 1, ifile)) < 0) { 
    222224                sipc_error(writer_ipc, "fread: %s\n", strerror(errno)); 
    223225                fclose(ifile); 
     
    322324} 
    323325 
    324 static void send_end_xmit(sipc_t *sipc) 
     326static void send_end_xmit(sipc_t * sipc) 
    325327{ 
    326328        char *data = sipc_get_data_ptr(sipc); 
     
    352354        } 
    353355 
    354         rbytes = fread(data, sizeof(char), DATA_LEN-1, ifile); 
     356        rbytes = fread(data, sizeof(char), DATA_LEN - 1, ifile); 
    355357        if (rbytes < 0) { 
    356358                fclose(ifile); 
  • trunk/libsipc/tests/test_ipc.c

    r34 r35  
    3333        /* Add suites to registry */ 
    3434        CU_SuiteInfo suites[] = { 
    35                 {"mq", test_mqueue_init, test_mqueue_cleanup, mqueue_tests}, 
    36                 {"shm", test_shm_init, test_shm_cleanup, shm_tests}, 
     35                {"mq", test_mqueue_init, test_mqueue_cleanup, mqueue_tests} 
     36                , 
     37                {"shm", test_shm_init, test_shm_cleanup, shm_tests} 
     38                , 
    3739                CU_SUITE_INFO_NULL 
    3840        }; 
     
    4345        CU_basic_run_tests(); 
    4446 
    45         printf("# suites run: %d, # tests run: %d\n", 
    46                CU_get_number_of_suites_run(), 
    47                CU_get_number_of_tests_run()); 
     47        printf("# suites run: %d, # tests run: %d\n", CU_get_number_of_suites_run(), CU_get_number_of_tests_run()); 
    4848 
    4949        CU_cleanup_registry();