Annotation of cci/usr/src/ucb/talk/ctl_transact.c, revision 1.1.1.1

1.1       root        1: #include "talk_ctl.h"
                      2: #include <sys/time.h>
                      3: 
                      4: #define CTL_WAIT 2     /* the amount of time to wait for a 
                      5:                           response, in seconds */
                      6: 
                      7: 
                      8: int    tonetmsg();
                      9: int    tonetresp();
                     10: int    frnetresp();
                     11: int    vaxbyteorder;
                     12: int    debug;
                     13: 
                     14:     /*
                     15:      * SOCKDGRAM is unreliable, so we must repeat messages if we have
                     16:      * not recieved an acknowledgement within a reasonable amount
                     17:      * of time
                     18:      */
                     19: 
                     20: ctl_transact(target, msg, type, response)
                     21: struct in_addr target;
                     22: CTL_MSG msg;
                     23: int type;
                     24: CTL_RESPONSE *response;
                     25: {
                     26:     struct sockaddr junk;
                     27:     int read_mask;
                     28:     int ctl_mask;
                     29:     int nready;
                     30:     int cc;
                     31:     int junk_size;
                     32:     struct timeval wait;
                     33: 
                     34:     NETCTL_MSG netmsg;         /* for conversion to net format */
                     35:     NETCTL_RESPONSE netresp;
                     36: 
                     37:     wait.tv_sec = CTL_WAIT;
                     38:     wait.tv_usec = 0;
                     39: 
                     40:     msg.ctlm_type = type;
                     41: 
                     42:     daemon_addr.sin_addr = target;
                     43:     daemon_addr.sin_port = daemon_port;
                     44: 
                     45:     ctl_mask = 1 << ctl_sockt;
                     46: 
                     47:     /*
                     48:      * keep sending the message until a response of the right
                     49:      * type is obtained
                     50:      */
                     51: 
                     52:     if (debug) {
                     53:        printf("send to this daemon" );
                     54:        print_addr(daemon_addr);
                     55:        print_request(&msg);
                     56:     }
                     57: 
                     58:     tonetmsg(&msg, &netmsg, vaxbyteorder);
                     59:     do {
                     60:            /* keep sending the message until a response is obtained */
                     61: 
                     62:        do {
                     63: 
                     64:            cc = sendto(ctl_sockt, (char *)&netmsg, sizeof(netmsg), 0,
                     65:                        &daemon_addr, sizeof(daemon_addr));
                     66: 
                     67:            if (cc != sizeof(netmsg)) {
                     68:                if (errno == EINTR) {
                     69:                        /* we are returning from an interupt */
                     70:                    continue;
                     71:                } else {
                     72:                    p_error("Error on write to talk daemon");
                     73:                }
                     74:            }
                     75: 
                     76:            read_mask = ctl_mask;
                     77: 
                     78:            while ((nready = select(32, &read_mask, 0, 0, &wait)) < 0) {
                     79:                if (errno == EINTR) {
                     80:                        /* we are returning from an interupt */
                     81:                    continue;
                     82:                } else {
                     83:                    p_error("Error on waiting for response from daemon");
                     84:                }
                     85:            }
                     86:        } while (nready == 0);
                     87: 
                     88:            /* keep reading while there are queued messages 
                     89:               (this is not necessary, it just saves extra
                     90:               request/acknowledgements being sent)
                     91:             */
                     92: 
                     93:        do {
                     94: 
                     95:            junk_size = sizeof(junk);
                     96:            cc = recvfrom(ctl_sockt, (char *) &netresp,
                     97:                           sizeof(netresp), 0, &junk, &junk_size );
                     98:            if (cc < 0) {
                     99:                if (errno == EINTR) {
                    100:                    continue;
                    101:                }
                    102:                if (debug) {
                    103:                        printf("ctl_sockt %d, cc %d\n", ctl_sockt, cc);
                    104:                        pause();
                    105:                }
                    106:                p_error("Error on read from talk daemon");
                    107:            }
                    108:            frnetresp(&netresp, response);
                    109:            if (debug) {
                    110:                printf("  ");
                    111:                print_response(response);
                    112:            }
                    113: 
                    114:            read_mask = ctl_mask;
                    115: 
                    116:                /* an immediate poll */
                    117: 
                    118:            timerclear(&wait);
                    119:            nready = select(32, &read_mask, 0, 0, &wait);
                    120: 
                    121:        } while ( nready > 0 && response->ctlr_type != type);
                    122: 
                    123:     } while (response->ctlr_type != type);
                    124: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.