home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume26 / mcast / part01 / libmcast / mc_shutdown.c < prev    next >
C/C++ Source or Header  |  1993-04-06  |  3KB  |  92 lines

  1. /*
  2.  * $Header: /u0/casey/src/mcast/libmcast/RCS/mc_shutdown.c,v 1.1 92/10/16 18:22:51 casey Exp $
  3.  */
  4.  
  5. /*
  6.  * Copyright (c) 1992 The Regents of the University of California.
  7.  * All rights reserved.
  8.  *
  9.  * Redistribution and use in source and binary forms, with or without
  10.  * modification, are permitted provided that the following conditions
  11.  * are met:
  12.  * 1. Redistributions of source code must retain the above copyright
  13.  *    notice, this list of conditions and the following disclaimer.
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in the
  16.  *    documentation and/or other materials provided with the distribution.
  17.  * 3. All advertising materials mentioning features or use of this software
  18.  *    must display the following acknowledgement:
  19.  *    This product includes software developed by the University of
  20.  *    California, Lawrence Livermore National Laboratory and its
  21.  *    contributors.
  22.  * 4. Neither the name of the University nor the names of its contributors
  23.  *    may be used to endorse or promote products derived from this software
  24.  *    without specific prior written permission.
  25.  *
  26.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  27.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  30.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  32.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  33.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  34.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  35.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  36.  * SUCH DAMAGE.
  37.  */
  38.  
  39. #ifndef lint
  40. static char rcsid[] = "$Header: /u0/casey/src/mcast/libmcast/RCS/mc_shutdown.c,v 1.1 92/10/16 18:22:51 casey Exp $";
  41. static char copyright[] =
  42.     "Copyright (c) 1992 The Regents of the University of California.\n"
  43.     "All rights reserved.\n";
  44. static char classification[] =
  45.     "Unclassified\n";
  46. #endif
  47.  
  48.  
  49. /*
  50.  * MCAST SYSLIB PUBLIC: mc_shutdown: shutdown(2) system call emulation routine.
  51.  */
  52.  
  53.  
  54. #include "mc_lib.h"
  55.  
  56.  
  57. int
  58. mc_shutdown(int s, int how)
  59. {
  60.     mc_state *sp = &_mc_state[s];
  61.     int mask;
  62.  
  63.     if (s < 0 || s >= MC_MAX_CONNECTIONS
  64.         || !(sp->state & MC_VALID)) {
  65.         /* return(close(s)); */
  66.         errno = EBADF;
  67.         return(-1);
  68.     }
  69.     if (how == 0)
  70.         mask = MC_SHUTDOWNRECV;
  71.     else if (how == 1)
  72.         mask = MC_SHUTDOWNSEND;
  73.     else if (how == 2)
  74.         mask = MC_SHUTDOWNRECV|MC_SHUTDOWNSEND;
  75.     else {
  76.         errno = EINVAL;
  77.         return(-1);
  78.     }
  79.     /* if SHUTDOWNRECV requested and we aren't already in that state ... */
  80.     if ((mask & ~sp->state) & MC_SHUTDOWNRECV) {
  81.         mcd_message command;
  82.  
  83.         (void)memset(&command, 0, sizeof(command));
  84.         command.request = htonl(MCD_SHUTDOWNRECV);
  85.         command.option = htonl(1);
  86.         if (_mc_write(s, &command, sizeof(command), 0, &MCD_MCADDR) < 0)
  87.             return(-1);
  88.     }
  89.     sp->state |= mask;
  90.     return(0);
  91. }
  92.