Hex Artifact Content

Artifact 089891ecdb896c6b431b52468ef218edc3665643:


0000: 2f 2a 0a 20 2a 20 43 6f 70 79 72 69 67 68 74 20  /*. * Copyright 
0010: 28 43 29 20 31 39 39 37 2d 31 39 39 39 20 4d 61  (C) 1997-1999 Ma
0020: 74 74 20 4e 65 77 6d 61 6e 20 3c 6d 61 74 74 40  tt Newman <matt@
0030: 6e 6f 76 61 64 69 67 6d 2e 63 6f 6d 3e 0a 20 2a  novadigm.com>. *
0040: 0a 20 2a 20 24 48 65 61 64 65 72 3a 20 2f 68 6f  . * $Header: /ho
0050: 6d 65 2f 72 6b 65 65 6e 65 2f 74 6d 70 2f 63 76  me/rkeene/tmp/cv
0060: 73 32 66 6f 73 73 69 6c 2f 2e 2e 2f 74 63 6c 74  s2fossil/../tclt
0070: 6c 73 2f 74 6c 73 2f 74 6c 73 2f 74 6c 73 42 49  ls/tls/tls/tlsBI
0080: 4f 2e 63 2c 76 20 31 2e 31 2e 31 2e 31 20 32 30  O.c,v 1.1.1.1 20
0090: 30 30 2f 30 31 2f 31 39 20 32 32 3a 31 30 3a 35  00/01/19 22:10:5
00a0: 38 20 61 62 6f 72 72 20 45 78 70 20 24 0a 20 2a  8 aborr Exp $. *
00b0: 0a 20 2a 20 50 72 6f 76 69 64 65 73 20 42 49 4f  . * Provides BIO
00c0: 20 6c 61 79 65 72 20 74 6f 20 69 6e 74 65 72 66   layer to interf
00d0: 61 63 65 20 6f 70 65 6e 73 73 6c 20 74 6f 20 54  ace openssl to T
00e0: 63 6c 2e 0a 20 2a 2f 0a 0a 23 69 6e 63 6c 75 64  cl.. */..#includ
00f0: 65 20 22 74 6c 73 49 6e 74 2e 68 22 0a 0a 2f 2a  e "tlsInt.h"../*
0100: 0a 20 2a 20 46 6f 72 77 61 72 64 20 64 65 63 6c  . * Forward decl
0110: 61 72 61 74 69 6f 6e 73 0a 20 2a 2f 0a 0a 73 74  arations. */..st
0120: 61 74 69 63 20 69 6e 74 20 42 69 6f 57 72 69 74  atic int BioWrit
0130: 65 09 5f 41 4e 53 49 5f 41 52 47 53 5f 20 28 28  e._ANSI_ARGS_ ((
0140: 42 49 4f 20 2a 68 2c 20 63 68 61 72 20 2a 62 75  BIO *h, char *bu
0150: 66 2c 20 69 6e 74 20 6e 75 6d 29 29 3b 0a 73 74  f, int num));.st
0160: 61 74 69 63 20 69 6e 74 20 42 69 6f 52 65 61 64  atic int BioRead
0170: 09 5f 41 4e 53 49 5f 41 52 47 53 5f 20 28 28 42  ._ANSI_ARGS_ ((B
0180: 49 4f 20 2a 68 2c 20 63 68 61 72 20 2a 62 75 66  IO *h, char *buf
0190: 2c 20 69 6e 74 20 6e 75 6d 29 29 3b 0a 73 74 61  , int num));.sta
01a0: 74 69 63 20 69 6e 74 20 42 69 6f 50 75 74 73 09  tic int BioPuts.
01b0: 5f 41 4e 53 49 5f 41 52 47 53 5f 20 28 28 42 49  _ANSI_ARGS_ ((BI
01c0: 4f 20 2a 68 2c 20 63 68 61 72 20 2a 73 74 72 29  O *h, char *str)
01d0: 29 3b 0a 73 74 61 74 69 63 20 6c 6f 6e 67 20 42  );.static long B
01e0: 69 6f 43 74 72 6c 09 5f 41 4e 53 49 5f 41 52 47  ioCtrl._ANSI_ARG
01f0: 53 5f 20 28 28 42 49 4f 20 2a 68 2c 20 69 6e 74  S_ ((BIO *h, int
0200: 20 63 6d 64 2c 20 6c 6f 6e 67 20 61 72 67 31 2c   cmd, long arg1,
0210: 20 63 68 61 72 20 2a 70 74 72 29 29 3b 0a 73 74   char *ptr));.st
0220: 61 74 69 63 20 69 6e 74 20 42 69 6f 4e 65 77 09  atic int BioNew.
0230: 5f 41 4e 53 49 5f 41 52 47 53 5f 20 28 28 42 49  _ANSI_ARGS_ ((BI
0240: 4f 20 2a 68 29 29 3b 0a 73 74 61 74 69 63 20 69  O *h));.static i
0250: 6e 74 20 42 69 6f 46 72 65 65 09 5f 41 4e 53 49  nt BioFree._ANSI
0260: 5f 41 52 47 53 5f 20 28 28 42 49 4f 20 2a 68 29  _ARGS_ ((BIO *h)
0270: 29 3b 0a 0a 0a 73 74 61 74 69 63 20 42 49 4f 5f  );...static BIO_
0280: 4d 45 54 48 4f 44 20 42 69 6f 4d 65 74 68 6f 64  METHOD BioMethod
0290: 73 20 3d 20 7b 0a 20 20 20 20 42 49 4f 5f 54 59  s = {.    BIO_TY
02a0: 50 45 5f 54 43 4c 2c 20 22 74 63 6c 22 2c 0a 20  PE_TCL, "tcl",. 
02b0: 20 20 20 42 69 6f 57 72 69 74 65 2c 0a 20 20 20     BioWrite,.   
02c0: 20 42 69 6f 52 65 61 64 2c 0a 20 20 20 20 42 69   BioRead,.    Bi
02d0: 6f 50 75 74 73 2c 0a 20 20 20 20 4e 55 4c 4c 2c  oPuts,.    NULL,
02e0: 09 2f 2a 20 42 69 6f 47 65 74 73 20 2a 2f 0a 20  ./* BioGets */. 
02f0: 20 20 20 42 69 6f 43 74 72 6c 2c 0a 20 20 20 20     BioCtrl,.    
0300: 42 69 6f 4e 65 77 2c 0a 20 20 20 20 42 69 6f 46  BioNew,.    BioF
0310: 72 65 65 2c 0a 7d 3b 0a 0a 42 49 4f 20 2a 0a 42  ree,.};..BIO *.B
0320: 49 4f 5f 6e 65 77 5f 74 63 6c 28 73 74 61 74 65  IO_new_tcl(state
0330: 50 74 72 2c 20 66 6c 61 67 73 29 0a 20 20 20 20  Ptr, flags).    
0340: 53 74 61 74 65 20 2a 73 74 61 74 65 50 74 72 3b  State *statePtr;
0350: 0a 20 20 20 20 69 6e 74 20 66 6c 61 67 73 3b 0a  .    int flags;.
0360: 7b 0a 20 20 20 20 42 49 4f 20 2a 62 69 6f 3b 0a  {.    BIO *bio;.
0370: 0a 20 20 20 20 62 69 6f 20 3d 20 42 49 4f 5f 6e  .    bio = BIO_n
0380: 65 77 28 26 42 69 6f 4d 65 74 68 6f 64 73 29 3b  ew(&BioMethods);
0390: 0a 20 20 20 20 62 69 6f 2d 3e 70 74 72 20 3d 20  .    bio->ptr = 
03a0: 28 63 68 61 72 2a 29 73 74 61 74 65 50 74 72 3b  (char*)statePtr;
03b0: 0a 20 20 20 20 62 69 6f 2d 3e 69 6e 69 74 20 3d  .    bio->init =
03c0: 20 31 3b 0a 20 20 20 20 62 69 6f 2d 3e 73 68 75   1;.    bio->shu
03d0: 74 64 6f 77 6e 20 3d 20 66 6c 61 67 73 3b 0a 0a  tdown = flags;..
03e0: 20 20 20 20 72 65 74 75 72 6e 20 62 69 6f 3b 0a      return bio;.
03f0: 7d 0a 0a 42 49 4f 5f 4d 45 54 48 4f 44 20 2a 0a  }..BIO_METHOD *.
0400: 42 49 4f 5f 73 5f 74 63 6c 28 29 0a 7b 0a 20 20  BIO_s_tcl().{.  
0410: 20 20 72 65 74 75 72 6e 20 26 42 69 6f 4d 65 74    return &BioMet
0420: 68 6f 64 73 3b 0a 7d 0a 0a 73 74 61 74 69 63 20  hods;.}..static 
0430: 69 6e 74 0a 42 69 6f 57 72 69 74 65 20 28 62 69  int.BioWrite (bi
0440: 6f 2c 20 62 75 66 2c 20 62 75 66 4c 65 6e 29 0a  o, buf, bufLen).
0450: 20 20 20 20 42 49 4f 20 2a 62 69 6f 3b 0a 20 20      BIO *bio;.  
0460: 20 20 63 68 61 72 20 2a 62 75 66 3b 0a 20 20 20    char *buf;.   
0470: 20 69 6e 74 20 62 75 66 4c 65 6e 3b 0a 7b 0a 20   int bufLen;.{. 
0480: 20 20 20 54 63 6c 5f 43 68 61 6e 6e 65 6c 20 63     Tcl_Channel c
0490: 68 61 6e 20 3d 20 54 6c 73 5f 47 65 74 50 61 72  han = Tls_GetPar
04a0: 65 6e 74 28 28 53 74 61 74 65 2a 29 62 69 6f 2d  ent((State*)bio-
04b0: 3e 70 74 72 29 3b 0a 20 20 20 20 69 6e 74 20 72  >ptr);.    int r
04c0: 65 74 3b 0a 0a 20 20 20 20 64 70 72 69 6e 74 66  et;..    dprintf
04d0: 28 73 74 64 65 72 72 2c 22 5c 6e 42 69 6f 57 72  (stderr,"\nBioWr
04e0: 69 74 65 28 30 78 25 78 2c 20 3c 62 75 66 3e 2c  ite(0x%x, <buf>,
04f0: 20 25 64 29 20 5b 30 78 25 78 5d 22 2c 20 62 69   %d) [0x%x]", bi
0500: 6f 2c 20 62 75 66 4c 65 6e 2c 20 63 68 61 6e 29  o, bufLen, chan)
0510: 3b 0a 0a 20 20 20 20 72 65 74 20 3d 20 54 63 6c  ;..    ret = Tcl
0520: 5f 57 72 69 74 65 28 20 63 68 61 6e 2c 20 62 75  _Write( chan, bu
0530: 66 2c 20 62 75 66 4c 65 6e 29 3b 0a 0a 20 20 20  f, bufLen);..   
0540: 20 64 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c   dprintf(stderr,
0550: 22 5c 6e 5b 30 78 25 78 5d 20 42 69 6f 57 72 69  "\n[0x%x] BioWri
0560: 74 65 28 25 64 29 20 2d 3e 20 25 64 20 5b 25 64  te(%d) -> %d [%d
0570: 2e 25 64 5d 22 2c 20 63 68 61 6e 2c 20 62 75 66  .%d]", chan, buf
0580: 4c 65 6e 2c 20 72 65 74 2c 0a 09 09 54 63 6c 5f  Len, ret,...Tcl_
0590: 45 6f 66 28 20 63 68 61 6e 29 2c 20 54 63 6c 5f  Eof( chan), Tcl_
05a0: 47 65 74 45 72 72 6e 6f 28 29 29 3b 0a 0a 20 20  GetErrno());..  
05b0: 20 20 42 49 4f 5f 63 6c 65 61 72 5f 66 6c 61 67    BIO_clear_flag
05c0: 73 28 62 69 6f 2c 20 42 49 4f 5f 46 4c 41 47 53  s(bio, BIO_FLAGS
05d0: 5f 57 52 49 54 45 7c 42 49 4f 5f 46 4c 41 47 53  _WRITE|BIO_FLAGS
05e0: 5f 53 48 4f 55 4c 44 5f 52 45 54 52 59 29 3b 0a  _SHOULD_RETRY);.
05f0: 0a 20 20 20 20 69 66 20 28 72 65 74 20 3d 3d 20  .    if (ret == 
0600: 30 29 20 7b 0a 09 69 66 20 28 21 54 63 6c 5f 45  0) {..if (!Tcl_E
0610: 6f 66 28 20 63 68 61 6e 29 29 20 7b 0a 09 20 20  of( chan)) {..  
0620: 20 20 42 49 4f 5f 73 65 74 5f 72 65 74 72 79 5f    BIO_set_retry_
0630: 77 72 69 74 65 28 62 69 6f 29 3b 0a 09 20 20 20  write(bio);..   
0640: 20 72 65 74 20 3d 20 2d 31 3b 0a 09 7d 0a 20 20   ret = -1;..}.  
0650: 20 20 7d 0a 20 20 20 20 69 66 20 28 42 49 4f 5f    }.    if (BIO_
0660: 73 68 6f 75 6c 64 5f 72 65 61 64 28 62 69 6f 29  should_read(bio)
0670: 29 0a 09 42 49 4f 5f 73 65 74 5f 72 65 74 72 79  )..BIO_set_retry
0680: 5f 72 65 61 64 28 62 69 6f 29 3b 0a 20 20 20 20  _read(bio);.    
0690: 72 65 74 75 72 6e 20 72 65 74 3b 0a 7d 0a 0a 73  return ret;.}..s
06a0: 74 61 74 69 63 20 69 6e 74 0a 42 69 6f 52 65 61  tatic int.BioRea
06b0: 64 20 28 62 69 6f 2c 20 62 75 66 2c 20 62 75 66  d (bio, buf, buf
06c0: 4c 65 6e 29 0a 20 20 20 20 42 49 4f 20 2a 62 69  Len).    BIO *bi
06d0: 6f 3b 0a 20 20 20 20 63 68 61 72 20 2a 62 75 66  o;.    char *buf
06e0: 3b 0a 20 20 20 20 69 6e 74 20 62 75 66 4c 65 6e  ;.    int bufLen
06f0: 3b 0a 7b 0a 20 20 20 20 54 63 6c 5f 43 68 61 6e  ;.{.    Tcl_Chan
0700: 6e 65 6c 20 63 68 61 6e 20 3d 20 54 6c 73 5f 47  nel chan = Tls_G
0710: 65 74 50 61 72 65 6e 74 28 28 53 74 61 74 65 2a  etParent((State*
0720: 29 62 69 6f 2d 3e 70 74 72 29 3b 0a 20 20 20 20  )bio->ptr);.    
0730: 69 6e 74 20 72 65 74 20 3d 20 30 3b 0a 0a 20 20  int ret = 0;..  
0740: 20 20 64 70 72 69 6e 74 66 28 73 74 64 65 72 72    dprintf(stderr
0750: 2c 22 5c 6e 42 69 6f 52 65 61 64 28 30 78 25 78  ,"\nBioRead(0x%x
0760: 2c 20 3c 62 75 66 3e 2c 20 25 64 29 20 5b 30 78  , <buf>, %d) [0x
0770: 25 78 5d 22 2c 20 62 69 6f 2c 20 62 75 66 4c 65  %x]", bio, bufLe
0780: 6e 2c 20 63 68 61 6e 29 3b 0a 0a 20 20 20 20 69  n, chan);..    i
0790: 66 20 28 62 75 66 20 3d 3d 20 4e 55 4c 4c 29 20  f (buf == NULL) 
07a0: 72 65 74 75 72 6e 20 30 3b 0a 0a 20 20 20 20 72  return 0;..    r
07b0: 65 74 20 3d 20 54 63 6c 5f 52 65 61 64 28 20 63  et = Tcl_Read( c
07c0: 68 61 6e 2c 20 62 75 66 2c 20 62 75 66 4c 65 6e  han, buf, bufLen
07d0: 29 3b 0a 0a 20 20 20 20 64 70 72 69 6e 74 66 28  );..    dprintf(
07e0: 73 74 64 65 72 72 2c 22 5c 6e 5b 30 78 25 78 5d  stderr,"\n[0x%x]
07f0: 20 42 69 6f 52 65 61 64 28 25 64 29 20 2d 3e 20   BioRead(%d) -> 
0800: 25 64 20 5b 25 64 2e 25 64 5d 22 2c 20 63 68 61  %d [%d.%d]", cha
0810: 6e 2c 20 62 75 66 4c 65 6e 2c 20 72 65 74 2c 0a  n, bufLen, ret,.
0820: 09 54 63 6c 5f 45 6f 66 28 63 68 61 6e 29 2c 20  .Tcl_Eof(chan), 
0830: 54 63 6c 5f 47 65 74 45 72 72 6e 6f 28 29 29 3b  Tcl_GetErrno());
0840: 0a 0a 20 20 20 20 42 49 4f 5f 63 6c 65 61 72 5f  ..    BIO_clear_
0850: 66 6c 61 67 73 28 62 69 6f 2c 20 42 49 4f 5f 46  flags(bio, BIO_F
0860: 4c 41 47 53 5f 52 45 41 44 7c 42 49 4f 5f 46 4c  LAGS_READ|BIO_FL
0870: 41 47 53 5f 53 48 4f 55 4c 44 5f 52 45 54 52 59  AGS_SHOULD_RETRY
0880: 29 3b 0a 0a 20 20 20 20 69 66 20 28 72 65 74 20  );..    if (ret 
0890: 3d 3d 20 30 29 20 7b 0a 09 69 66 20 28 21 54 63  == 0) {..if (!Tc
08a0: 6c 5f 45 6f 66 28 20 63 68 61 6e 29 29 20 7b 0a  l_Eof( chan)) {.
08b0: 09 20 20 20 20 42 49 4f 5f 73 65 74 5f 72 65 74  .    BIO_set_ret
08c0: 72 79 5f 72 65 61 64 28 62 69 6f 29 3b 0a 09 20  ry_read(bio);.. 
08d0: 20 20 20 72 65 74 20 3d 20 2d 31 3b 0a 09 7d 0a     ret = -1;..}.
08e0: 20 20 20 20 7d 0a 20 20 20 20 69 66 20 28 42 49      }.    if (BI
08f0: 4f 5f 73 68 6f 75 6c 64 5f 77 72 69 74 65 28 62  O_should_write(b
0900: 69 6f 29 29 0a 09 42 49 4f 5f 73 65 74 5f 72 65  io))..BIO_set_re
0910: 74 72 79 5f 77 72 69 74 65 28 62 69 6f 29 3b 0a  try_write(bio);.
0920: 20 20 20 20 72 65 74 75 72 6e 20 72 65 74 3b 0a      return ret;.
0930: 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 0a 42 69  }..static int.Bi
0940: 6f 50 75 74 73 09 28 62 69 6f 2c 20 73 74 72 29  oPuts.(bio, str)
0950: 0a 20 20 20 20 42 49 4f 20 2a 62 69 6f 3b 0a 20  .    BIO *bio;. 
0960: 20 20 20 63 68 61 72 20 2a 73 74 72 3b 0a 7b 0a     char *str;.{.
0970: 20 20 20 20 72 65 74 75 72 6e 20 42 69 6f 57 72      return BioWr
0980: 69 74 65 28 20 62 69 6f 2c 20 73 74 72 2c 20 73  ite( bio, str, s
0990: 74 72 6c 65 6e 28 73 74 72 29 29 3b 0a 7d 0a 0a  trlen(str));.}..
09a0: 73 74 61 74 69 63 20 6c 6f 6e 67 0a 42 69 6f 43  static long.BioC
09b0: 74 72 6c 09 28 62 69 6f 2c 20 63 6d 64 2c 20 6e  trl.(bio, cmd, n
09c0: 75 6d 2c 20 70 74 72 29 0a 20 20 20 20 42 49 4f  um, ptr).    BIO
09d0: 20 2a 62 69 6f 3b 0a 20 20 20 20 69 6e 74 20 63   *bio;.    int c
09e0: 6d 64 3b 0a 20 20 20 20 6c 6f 6e 67 20 6e 75 6d  md;.    long num
09f0: 3b 0a 20 20 20 20 63 68 61 72 20 2a 70 74 72 3b  ;.    char *ptr;
0a00: 0a 7b 0a 20 20 20 20 54 63 6c 5f 43 68 61 6e 6e  .{.    Tcl_Chann
0a10: 65 6c 20 63 68 61 6e 20 3d 20 54 6c 73 5f 47 65  el chan = Tls_Ge
0a20: 74 50 61 72 65 6e 74 28 28 53 74 61 74 65 2a 29  tParent((State*)
0a30: 62 69 6f 2d 3e 70 74 72 29 3b 0a 20 20 20 20 6c  bio->ptr);.    l
0a40: 6f 6e 67 20 72 65 74 20 3d 20 31 3b 0a 20 20 20  ong ret = 1;.   
0a50: 20 69 6e 74 20 2a 69 70 3b 0a 0a 20 20 20 20 64   int *ip;..    d
0a60: 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c 22 5c  printf(stderr,"\
0a70: 6e 42 69 6f 43 74 72 6c 28 30 78 25 78 2c 20 30  nBioCtrl(0x%x, 0
0a80: 78 25 78 2c 20 30 78 25 78 2c 20 30 78 25 78 29  x%x, 0x%x, 0x%x)
0a90: 22 2c 20 62 69 6f 2c 20 63 6d 64 2c 20 6e 75 6d  ", bio, cmd, num
0aa0: 2c 20 70 74 72 29 3b 0a 0a 20 20 20 20 73 77 69  , ptr);..    swi
0ab0: 74 63 68 20 28 63 6d 64 29 20 7b 0a 20 20 20 20  tch (cmd) {.    
0ac0: 63 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f 52 45  case BIO_CTRL_RE
0ad0: 53 45 54 3a 0a 09 6e 75 6d 20 3d 20 30 3b 0a 20  SET:..num = 0;. 
0ae0: 20 20 20 63 61 73 65 20 42 49 4f 5f 43 5f 46 49     case BIO_C_FI
0af0: 4c 45 5f 53 45 45 4b 3a 0a 20 20 20 20 63 61 73  LE_SEEK:.    cas
0b00: 65 20 42 49 4f 5f 43 5f 46 49 4c 45 5f 54 45 4c  e BIO_C_FILE_TEL
0b10: 4c 3a 0a 09 72 65 74 20 3d 20 30 3b 0a 09 62 72  L:..ret = 0;..br
0b20: 65 61 6b 3b 0a 20 20 20 20 63 61 73 65 20 42 49  eak;.    case BI
0b30: 4f 5f 43 54 52 4c 5f 49 4e 46 4f 3a 0a 09 72 65  O_CTRL_INFO:..re
0b40: 74 20 3d 20 31 3b 0a 09 62 72 65 61 6b 3b 0a 20  t = 1;..break;. 
0b50: 20 20 20 63 61 73 65 20 42 49 4f 5f 43 5f 53 45     case BIO_C_SE
0b60: 54 5f 46 44 3a 0a 09 42 69 6f 46 72 65 65 28 62  T_FD:..BioFree(b
0b70: 69 6f 29 3b 0a 09 2f 2a 20 53 65 74 73 20 53 74  io);../* Sets St
0b80: 61 74 65 2a 20 2a 2f 0a 09 62 69 6f 2d 3e 70 74  ate* */..bio->pt
0b90: 72 20 3d 20 2a 28 28 63 68 61 72 20 2a 2a 29 70  r = *((char **)p
0ba0: 74 72 29 3b 0a 09 62 69 6f 2d 3e 73 68 75 74 64  tr);..bio->shutd
0bb0: 6f 77 6e 20 3d 20 28 69 6e 74 29 6e 75 6d 3b 0a  own = (int)num;.
0bc0: 09 62 69 6f 2d 3e 69 6e 69 74 20 3d 20 31 3b 0a  .bio->init = 1;.
0bd0: 09 62 72 65 61 6b 3b 0a 20 20 20 20 63 61 73 65  .break;.    case
0be0: 20 42 49 4f 5f 43 5f 47 45 54 5f 46 44 3a 0a 09   BIO_C_GET_FD:..
0bf0: 69 66 20 28 62 69 6f 2d 3e 69 6e 69 74 29 20 7b  if (bio->init) {
0c00: 0a 09 20 20 20 20 69 70 3d 28 69 6e 74 20 2a 29  ..    ip=(int *)
0c10: 70 74 72 3b 0a 09 20 20 20 20 69 66 20 28 69 70  ptr;..    if (ip
0c20: 20 21 3d 20 4e 55 4c 4c 29 20 2a 69 70 3d 62 69   != NULL) *ip=bi
0c30: 6f 2d 3e 6e 75 6d 3b 0a 09 09 72 65 74 3d 62 69  o->num;...ret=bi
0c40: 6f 2d 3e 6e 75 6d 3b 0a 09 7d 20 65 6c 73 65 20  o->num;..} else 
0c50: 7b 0a 09 20 20 20 20 72 65 74 3d 20 2d 31 3b 0a  {..    ret= -1;.
0c60: 09 7d 0a 09 62 72 65 61 6b 3b 0a 20 20 20 20 63  .}..break;.    c
0c70: 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f 47 45 54  ase BIO_CTRL_GET
0c80: 5f 43 4c 4f 53 45 3a 0a 09 72 65 74 3d 62 69 6f  _CLOSE:..ret=bio
0c90: 2d 3e 73 68 75 74 64 6f 77 6e 3b 0a 09 62 72 65  ->shutdown;..bre
0ca0: 61 6b 3b 0a 20 20 20 20 63 61 73 65 20 42 49 4f  ak;.    case BIO
0cb0: 5f 43 54 52 4c 5f 53 45 54 5f 43 4c 4f 53 45 3a  _CTRL_SET_CLOSE:
0cc0: 0a 09 62 69 6f 2d 3e 73 68 75 74 64 6f 77 6e 3d  ..bio->shutdown=
0cd0: 28 69 6e 74 29 6e 75 6d 3b 0a 09 62 72 65 61 6b  (int)num;..break
0ce0: 3b 0a 20 20 20 20 63 61 73 65 20 42 49 4f 5f 43  ;.    case BIO_C
0cf0: 54 52 4c 5f 45 4f 46 3a 0a 09 64 70 72 69 6e 74  TRL_EOF:..dprint
0d00: 66 28 73 74 64 65 72 72 2c 20 22 42 49 4f 5f 43  f(stderr, "BIO_C
0d10: 54 52 4c 5f 45 4f 46 5c 6e 22 29 3b 0a 09 72 65  TRL_EOF\n");..re
0d20: 74 20 3d 20 54 63 6c 5f 45 6f 66 28 20 63 68 61  t = Tcl_Eof( cha
0d30: 6e 29 3b 0a 09 62 72 65 61 6b 3b 0a 20 20 20 20  n);..break;.    
0d40: 63 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f 50 45  case BIO_CTRL_PE
0d50: 4e 44 49 4e 47 3a 0a 09 69 66 20 28 54 63 6c 5f  NDING:..if (Tcl_
0d60: 49 6e 70 75 74 42 75 66 66 65 72 65 64 28 63 68  InputBuffered(ch
0d70: 61 6e 29 29 0a 09 20 20 20 20 72 65 74 20 3d 20  an))..    ret = 
0d80: 31 3b 0a 09 65 6c 73 65 0a 09 20 20 20 20 72 65  1;..else..    re
0d90: 74 20 3d 20 30 3b 0a 09 64 70 72 69 6e 74 66 28  t = 0;..dprintf(
0da0: 73 74 64 65 72 72 2c 20 22 42 49 4f 5f 43 54 52  stderr, "BIO_CTR
0db0: 4c 5f 50 45 4e 44 49 4e 47 28 25 64 29 5c 6e 22  L_PENDING(%d)\n"
0dc0: 2c 20 72 65 74 29 3b 0a 09 62 72 65 61 6b 3b 0a  , ret);..break;.
0dd0: 20 20 20 20 63 61 73 65 20 42 49 4f 5f 43 54 52      case BIO_CTR
0de0: 4c 5f 57 50 45 4e 44 49 4e 47 3a 0a 09 72 65 74  L_WPENDING:..ret
0df0: 3d 30 3b 0a 09 62 72 65 61 6b 3b 0a 20 20 20 20  =0;..break;.    
0e00: 63 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f 44 55  case BIO_CTRL_DU
0e10: 50 3a 0a 09 62 72 65 61 6b 3b 0a 20 20 20 20 63  P:..break;.    c
0e20: 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f 46 4c 55  ase BIO_CTRL_FLU
0e30: 53 48 3a 0a 09 64 70 72 69 6e 74 66 28 73 74 64  SH:..dprintf(std
0e40: 65 72 72 2c 20 22 42 49 4f 5f 43 54 52 4c 5f 46  err, "BIO_CTRL_F
0e50: 4c 55 53 48 5c 6e 22 29 3b 0a 09 69 66 20 28 54  LUSH\n");..if (T
0e60: 63 6c 5f 46 6c 75 73 68 28 20 63 68 61 6e 29 20  cl_Flush( chan) 
0e70: 3d 3d 20 54 43 4c 5f 4f 4b 29 0a 09 20 20 20 20  == TCL_OK)..    
0e80: 72 65 74 3d 31 3b 0a 09 65 6c 73 65 0a 09 20 20  ret=1;..else..  
0e90: 20 20 72 65 74 3d 2d 31 3b 0a 09 62 72 65 61 6b    ret=-1;..break
0ea0: 3b 0a 20 20 20 20 64 65 66 61 75 6c 74 3a 0a 09  ;.    default:..
0eb0: 72 65 74 3d 30 3b 0a 09 62 72 65 61 6b 3b 0a 20  ret=0;..break;. 
0ec0: 20 20 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 28     }.    return(
0ed0: 72 65 74 29 3b 0a 7d 0a 0a 73 74 61 74 69 63 20  ret);.}..static 
0ee0: 69 6e 74 0a 42 69 6f 4e 65 77 09 28 62 69 6f 29  int.BioNew.(bio)
0ef0: 0a 20 20 20 20 42 49 4f 20 2a 62 69 6f 3b 0a 7b  .    BIO *bio;.{
0f00: 0a 20 20 20 20 62 69 6f 2d 3e 69 6e 69 74 20 3d  .    bio->init =
0f10: 20 30 3b 0a 20 20 20 20 62 69 6f 2d 3e 6e 75 6d   0;.    bio->num
0f20: 20 3d 20 30 3b 0a 20 20 20 20 62 69 6f 2d 3e 70   = 0;.    bio->p
0f30: 74 72 20 3d 20 4e 55 4c 4c 3b 0a 20 20 20 20 62  tr = NULL;.    b
0f40: 69 6f 2d 3e 66 6c 61 67 73 20 3d 20 30 3b 0a 0a  io->flags = 0;..
0f50: 20 20 20 20 72 65 74 75 72 6e 20 31 3b 0a 7d 0a      return 1;.}.
0f60: 0a 73 74 61 74 69 63 20 69 6e 74 0a 42 69 6f 46  .static int.BioF
0f70: 72 65 65 09 28 62 69 6f 29 0a 20 20 20 20 42 49  ree.(bio).    BI
0f80: 4f 20 2a 62 69 6f 3b 0a 7b 0a 20 20 20 20 69 66  O *bio;.{.    if
0f90: 20 28 62 69 6f 20 3d 3d 20 4e 55 4c 4c 29 0a 09   (bio == NULL)..
0fa0: 72 65 74 75 72 6e 20 30 3b 0a 0a 20 20 20 20 69  return 0;..    i
0fb0: 66 20 28 62 69 6f 2d 3e 73 68 75 74 64 6f 77 6e  f (bio->shutdown
0fc0: 29 20 7b 0a 09 69 66 20 28 62 69 6f 2d 3e 69 6e  ) {..if (bio->in
0fd0: 69 74 29 20 7b 0a 09 20 20 20 20 2f 2a 73 68 75  it) {..    /*shu
0fe0: 74 64 6f 77 6e 28 62 69 6f 2d 3e 6e 75 6d 2c 20  tdown(bio->num, 
0ff0: 32 29 20 2a 2f 0a 09 20 20 20 20 2f 2a 63 6c 6f  2) */..    /*clo
1000: 73 65 73 6f 63 6b 65 74 28 62 69 6f 2d 3e 6e 75  sesocket(bio->nu
1010: 6d 29 20 2a 2f 0a 09 7d 0a 09 62 69 6f 2d 3e 69  m) */..}..bio->i
1020: 6e 69 74 20 3d 20 30 3b 0a 09 62 69 6f 2d 3e 66  nit = 0;..bio->f
1030: 6c 61 67 73 20 3d 20 30 3b 0a 09 62 69 6f 2d 3e  lags = 0;..bio->
1040: 6e 75 6d 20 3d 20 30 3b 0a 20 20 20 20 7d 0a 20  num = 0;.    }. 
1050: 20 20 20 72 65 74 75 72 6e 20 31 3b 0a 7d 0a        return 1;.}.