Annotation of 42BSD/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:     /*
                      9:      * SOCKDGRAM is unreliable, so we must repeat messages if we have
                     10:      * not recieved an acknowledgement within a reasonable amount
                     11:      * of time
                     12:      */
                     13: 
                     14: ctl_transact(target, msg, type, response)
                     15: struct in_addr target;
                     16: CTL_MSG msg;
                     17: int type;
                     18: CTL_RESPONSE *response;
                     19: {
                     20:     struct sockaddr junk;
                     21:     int read_mask;
                     22:     int ctl_mask;
                     23:     int nready;
                     24:     int cc;
                     25:     int junk_size;
                     26:     struct timeval wait;
                     27: 
                     28:     wait.tv_sec = CTL_WAIT;
                     29:     wait.tv_usec = 0;
                     30: 
                     31:     msg.type = type;
                     32: 
                     33:     daemon_addr.sin_addr = target;
                     34:     daemon_addr.sin_port = daemon_port;
                     35: 
                     36:     ctl_mask = 1 << ctl_sockt;
                     37: 
                     38:        /*
                     39:         * keep sending the message until a response of the right
                     40:         * type is obtained
                     41:         */
                     42:     do {
                     43:            /* keep sending the message until a response is obtained */
                     44: 
                     45:        do {
                     46:            cc = sendto(ctl_sockt, (char *)&msg, sizeof(CTL_MSG), 0,
                     47:                        &daemon_addr, sizeof(daemon_addr));
                     48: 
                     49:            if (cc != sizeof(CTL_MSG)) {
                     50:                if (errno == EINTR) {
                     51:                        /* we are returning from an interupt */
                     52:                    continue;
                     53:                } else {
                     54:                    p_error("Error on write to talk daemon");
                     55:                }
                     56:            }
                     57: 
                     58:            read_mask = ctl_mask;
                     59: 
                     60:            while ((nready = select(32, &read_mask, 0, 0, &wait)) < 0) {
                     61:                if (errno == EINTR) {
                     62:                        /* we are returning from an interupt */
                     63:                    continue;
                     64:                } else {
                     65:                    p_error("Error on waiting for response from daemon");
                     66:                }
                     67:            }
                     68:        } while (nready == 0);
                     69: 
                     70:            /* keep reading while there are queued messages 
                     71:               (this is not necessary, it just saves extra
                     72:               request/acknowledgements being sent)
                     73:             */
                     74: 
                     75:        do {
                     76: 
                     77:            junk_size = sizeof(junk);
                     78:            cc = recvfrom(ctl_sockt, (char *) response,
                     79:                           sizeof(CTL_RESPONSE), 0, &junk, &junk_size );
                     80:            if (cc < 0) {
                     81:                if (errno == EINTR) {
                     82:                    continue;
                     83:                }
                     84:                p_error("Error on read from talk daemon");
                     85:            }
                     86: 
                     87:            read_mask = ctl_mask;
                     88: 
                     89:                /* an immediate poll */
                     90: 
                     91:            timerclear(&wait);
                     92:            nready = select(32, &read_mask, 0, 0, &wait);
                     93: 
                     94:        } while ( nready > 0 && response->type != type);
                     95: 
                     96:     } while (response->type != type);
                     97: }

unix.superglobalmegacorp.com

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