Annotation of XNU/bsd/netat/adsp_attention.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             6:  * The contents of this file constitute Original Code as defined in and
        !             7:  * are subject to the Apple Public Source License Version 1.1 (the
        !             8:  * "License").  You may not use this file except in compliance with the
        !             9:  * License.  Please obtain a copy of the License at
        !            10:  * http://www.apple.com/publicsource and read it before using this file.
        !            11:  * 
        !            12:  * This Original Code and all software distributed under the License are
        !            13:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
        !            14:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
        !            15:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
        !            16:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
        !            17:  * License for the specific language governing rights and limitations
        !            18:  * under the License.
        !            19:  * 
        !            20:  * @APPLE_LICENSE_HEADER_END@
        !            21:  */
        !            22: /* 
        !            23:  * dspAttention.c 
        !            24:  *
        !            25:  * From Mike Shoemaker v01.05  03/16/90 mbs
        !            26:  */
        !            27: /*
        !            28:  * Change log:
        !            29:  *   06/29/95 - Modified to handle flow control for writing (Tuyen Nguyen)
        !            30:  *    Modified for MP, 1996 by Tuyen Nguyen
        !            31:  *   Modified, April 9, 1997 by Tuyen Nguyen for MacOSX.
        !            32:  */
        !            33: 
        !            34: #include <sys/errno.h>
        !            35: #include <sys/types.h>
        !            36: #include <sys/param.h>
        !            37: #include <machine/spl.h>
        !            38: #include <sys/systm.h>
        !            39: #include <sys/kernel.h>
        !            40: #include <sys/proc.h>
        !            41: #include <sys/filedesc.h>
        !            42: #include <sys/fcntl.h>
        !            43: #include <sys/mbuf.h>
        !            44: #include <sys/socket.h>
        !            45: 
        !            46: #include <netat/sysglue.h>
        !            47: #include <netat/appletalk.h>
        !            48: #include <netat/at_pcb.h>
        !            49: #include <netat/debug.h>
        !            50: #include <netat/adsp.h>
        !            51: #include <netat/adsp_internal.h>
        !            52: 
        !            53: /*
        !            54:  * dspAttention
        !            55:  * 
        !            56:  * INPUTS:
        !            57:  *     --> ccbRefNum           refnum of connection end
        !            58:  *     --> attnCode            client attention code
        !            59:  *     --> attnSize            size in bytes of attention data
        !            60:  *     --> attnData            pointer to attention data
        !            61:  *     --> attnInterval        attention retransmit interval 
        !            62:  *                             (ignored by ADSP 1.5 & up)
        !            63:  *
        !            64:  * OUTPUTS:
        !            65:  *     none
        !            66:  *
        !            67:  * ERRORS:
        !            68:  *     errRefNum               bad connection refnum
        !            69:  *     errState                connection is not open
        !            70:  *     errAttention            attention message too long
        !            71:  *     errAborted              request aborted by Remove or Close call
        !            72:  */
        !            73: int adspAttention(sp, pb)      /* (DSPPBPtr pb) */
        !            74:     register struct adspcmd *pb;
        !            75:     register CCBPtr sp;
        !            76: {
        !            77:     int        s;
        !            78:     register gbuf_t *mp, *nmp;
        !            79:     unsigned char uerr;
        !            80:        
        !            81:     if (sp == 0) {
        !            82:        pb->ioResult = errRefNum;
        !            83:        return EINVAL;
        !            84:     }
        !            85:        
        !            86:     if (sp->state != sOpen) {  /* If we're not open, tell user to go away */
        !            87:        pb->ioResult = errState;
        !            88:        uerr = ENOTCONN;
        !            89: l_err:
        !            90:        atalk_notify(sp->gref, uerr);
        !            91:        gbuf_freem(pb->mp);
        !            92:        return 0;
        !            93:     }
        !            94:        
        !            95:     if (pb->u.attnParams.attnSize > attnBufSize) /* If data too big, bye-bye */
        !            96:     {
        !            97:        pb->ioResult = errAttention;
        !            98:        uerr = ERANGE;
        !            99:        goto l_err;
        !           100:     }
        !           101: 
        !           102:     /* The 1st mbuf in the pb->mp chain (mp) is the adspcmd structure. 
        !           103:        The 2nd mbuf (nmp) will be the beginning of the data. */
        !           104:     mp = pb->mp;
        !           105:     if (pb->u.attnParams.attnSize) {
        !           106:         nmp = gbuf_cont(mp);
        !           107:        if (gbuf_len(mp) > sizeof(struct adspcmd)) {
        !           108:            if ((nmp = gbuf_dupb(mp)) == 0) {
        !           109:                gbuf_wset(mp, sizeof(struct adspcmd));
        !           110:                uerr = ENOBUFS;
        !           111:                goto l_err;
        !           112:            }
        !           113:            gbuf_wset(mp, sizeof(struct adspcmd));
        !           114:            gbuf_rinc(nmp, sizeof(struct adspcmd));
        !           115:            gbuf_cont(nmp) = gbuf_cont(mp);
        !           116:            gbuf_cont(mp) = nmp;
        !           117:        }
        !           118:     }
        !           119:     pb->ioDirection = 1;       /* outgoing attention data */
        !           120:     ATDISABLE(s, sp->lock);
        !           121:     if (sp->sapb) {            /* Pending attentions already? */
        !           122:        qAddToEnd(&sp->sapb, pb); /* Just add to end of queue */
        !           123:        ATENABLE(s, sp->lock);
        !           124:     } else {
        !           125:        sp->sendAttnData = 1;   /* Start off this attention */
        !           126:        pb->qLink = 0;
        !           127:        sp->sapb = pb;
        !           128:        ATENABLE(s, sp->lock);
        !           129:        CheckSend(sp);
        !           130:     }
        !           131:     pb->ioResult = 1;  /* indicate that the IO is not complete */
        !           132:     return 0;
        !           133: }

unix.superglobalmegacorp.com

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