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 32 30 30 30 20 4d 61  (C) 1997-2000 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 32 20 32 30 30 30 2f 30  O.c,v 1.2 2000/0
0090: 31 2f 32 30 20 30 31 3a 35 31 3a 33 39 20 61 62  1/20 01:51:39 ab
00a0: 6f 72 72 20 45 78 70 20 24 0a 20 2a 0a 20 2a 20  orr Exp $. *. * 
00b0: 50 72 6f 76 69 64 65 73 20 42 49 4f 20 6c 61 79  Provides BIO lay
00c0: 65 72 20 74 6f 20 69 6e 74 65 72 66 61 63 65 20  er to interface 
00d0: 6f 70 65 6e 73 73 6c 20 74 6f 20 54 63 6c 2e 0a  openssl to Tcl..
00e0: 20 2a 2f 0a 0a 23 69 6e 63 6c 75 64 65 20 22 74   */..#include "t
00f0: 6c 73 49 6e 74 2e 68 22 0a 0a 2f 2a 0a 20 2a 20  lsInt.h"../*. * 
0100: 46 6f 72 77 61 72 64 20 64 65 63 6c 61 72 61 74  Forward declarat
0110: 69 6f 6e 73 0a 20 2a 2f 0a 0a 73 74 61 74 69 63  ions. */..static
0120: 20 69 6e 74 20 42 69 6f 57 72 69 74 65 09 5f 41   int BioWrite._A
0130: 4e 53 49 5f 41 52 47 53 5f 20 28 28 42 49 4f 20  NSI_ARGS_ ((BIO 
0140: 2a 68 2c 20 63 68 61 72 20 2a 62 75 66 2c 20 69  *h, char *buf, i
0150: 6e 74 20 6e 75 6d 29 29 3b 0a 73 74 61 74 69 63  nt num));.static
0160: 20 69 6e 74 20 42 69 6f 52 65 61 64 09 5f 41 4e   int BioRead._AN
0170: 53 49 5f 41 52 47 53 5f 20 28 28 42 49 4f 20 2a  SI_ARGS_ ((BIO *
0180: 68 2c 20 63 68 61 72 20 2a 62 75 66 2c 20 69 6e  h, char *buf, in
0190: 74 20 6e 75 6d 29 29 3b 0a 73 74 61 74 69 63 20  t num));.static 
01a0: 69 6e 74 20 42 69 6f 50 75 74 73 09 5f 41 4e 53  int BioPuts._ANS
01b0: 49 5f 41 52 47 53 5f 20 28 28 42 49 4f 20 2a 68  I_ARGS_ ((BIO *h
01c0: 2c 20 63 68 61 72 20 2a 73 74 72 29 29 3b 0a 73  , char *str));.s
01d0: 74 61 74 69 63 20 6c 6f 6e 67 20 42 69 6f 43 74  tatic long BioCt
01e0: 72 6c 09 5f 41 4e 53 49 5f 41 52 47 53 5f 20 28  rl._ANSI_ARGS_ (
01f0: 28 42 49 4f 20 2a 68 2c 20 69 6e 74 20 63 6d 64  (BIO *h, int cmd
0200: 2c 20 6c 6f 6e 67 20 61 72 67 31 2c 20 63 68 61  , long arg1, cha
0210: 72 20 2a 70 74 72 29 29 3b 0a 73 74 61 74 69 63  r *ptr));.static
0220: 20 69 6e 74 20 42 69 6f 4e 65 77 09 5f 41 4e 53   int BioNew._ANS
0230: 49 5f 41 52 47 53 5f 20 28 28 42 49 4f 20 2a 68  I_ARGS_ ((BIO *h
0240: 29 29 3b 0a 73 74 61 74 69 63 20 69 6e 74 20 42  ));.static int B
0250: 69 6f 46 72 65 65 09 5f 41 4e 53 49 5f 41 52 47  ioFree._ANSI_ARG
0260: 53 5f 20 28 28 42 49 4f 20 2a 68 29 29 3b 0a 0a  S_ ((BIO *h));..
0270: 0a 73 74 61 74 69 63 20 42 49 4f 5f 4d 45 54 48  .static BIO_METH
0280: 4f 44 20 42 69 6f 4d 65 74 68 6f 64 73 20 3d 20  OD BioMethods = 
0290: 7b 0a 20 20 20 20 42 49 4f 5f 54 59 50 45 5f 54  {.    BIO_TYPE_T
02a0: 43 4c 2c 20 22 74 63 6c 22 2c 0a 20 20 20 20 42  CL, "tcl",.    B
02b0: 69 6f 57 72 69 74 65 2c 0a 20 20 20 20 42 69 6f  ioWrite,.    Bio
02c0: 52 65 61 64 2c 0a 20 20 20 20 42 69 6f 50 75 74  Read,.    BioPut
02d0: 73 2c 0a 20 20 20 20 4e 55 4c 4c 2c 09 2f 2a 20  s,.    NULL,./* 
02e0: 42 69 6f 47 65 74 73 20 2a 2f 0a 20 20 20 20 42  BioGets */.    B
02f0: 69 6f 43 74 72 6c 2c 0a 20 20 20 20 42 69 6f 4e  ioCtrl,.    BioN
0300: 65 77 2c 0a 20 20 20 20 42 69 6f 46 72 65 65 2c  ew,.    BioFree,
0310: 0a 7d 3b 0a 0a 42 49 4f 20 2a 0a 42 49 4f 5f 6e  .};..BIO *.BIO_n
0320: 65 77 5f 74 63 6c 28 73 74 61 74 65 50 74 72 2c  ew_tcl(statePtr,
0330: 20 66 6c 61 67 73 29 0a 20 20 20 20 53 74 61 74   flags).    Stat
0340: 65 20 2a 73 74 61 74 65 50 74 72 3b 0a 20 20 20  e *statePtr;.   
0350: 20 69 6e 74 20 66 6c 61 67 73 3b 0a 7b 0a 20 20   int flags;.{.  
0360: 20 20 42 49 4f 20 2a 62 69 6f 3b 0a 0a 20 20 20    BIO *bio;..   
0370: 20 62 69 6f 20 3d 20 42 49 4f 5f 6e 65 77 28 26   bio = BIO_new(&
0380: 42 69 6f 4d 65 74 68 6f 64 73 29 3b 0a 20 20 20  BioMethods);.   
0390: 20 62 69 6f 2d 3e 70 74 72 20 3d 20 28 63 68 61   bio->ptr = (cha
03a0: 72 2a 29 73 74 61 74 65 50 74 72 3b 0a 20 20 20  r*)statePtr;.   
03b0: 20 62 69 6f 2d 3e 69 6e 69 74 20 3d 20 31 3b 0a   bio->init = 1;.
03c0: 20 20 20 20 62 69 6f 2d 3e 73 68 75 74 64 6f 77      bio->shutdow
03d0: 6e 20 3d 20 66 6c 61 67 73 3b 0a 0a 20 20 20 20  n = flags;..    
03e0: 72 65 74 75 72 6e 20 62 69 6f 3b 0a 7d 0a 0a 42  return bio;.}..B
03f0: 49 4f 5f 4d 45 54 48 4f 44 20 2a 0a 42 49 4f 5f  IO_METHOD *.BIO_
0400: 73 5f 74 63 6c 28 29 0a 7b 0a 20 20 20 20 72 65  s_tcl().{.    re
0410: 74 75 72 6e 20 26 42 69 6f 4d 65 74 68 6f 64 73  turn &BioMethods
0420: 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 0a  ;.}..static int.
0430: 42 69 6f 57 72 69 74 65 20 28 62 69 6f 2c 20 62  BioWrite (bio, b
0440: 75 66 2c 20 62 75 66 4c 65 6e 29 0a 20 20 20 20  uf, bufLen).    
0450: 42 49 4f 20 2a 62 69 6f 3b 0a 20 20 20 20 63 68  BIO *bio;.    ch
0460: 61 72 20 2a 62 75 66 3b 0a 20 20 20 20 69 6e 74  ar *buf;.    int
0470: 20 62 75 66 4c 65 6e 3b 0a 7b 0a 20 20 20 20 54   bufLen;.{.    T
0480: 63 6c 5f 43 68 61 6e 6e 65 6c 20 63 68 61 6e 20  cl_Channel chan 
0490: 3d 20 54 6c 73 5f 47 65 74 50 61 72 65 6e 74 28  = Tls_GetParent(
04a0: 28 53 74 61 74 65 2a 29 62 69 6f 2d 3e 70 74 72  (State*)bio->ptr
04b0: 29 3b 0a 20 20 20 20 69 6e 74 20 72 65 74 3b 0a  );.    int ret;.
04c0: 0a 20 20 20 20 64 70 72 69 6e 74 66 28 73 74 64  .    dprintf(std
04d0: 65 72 72 2c 22 5c 6e 42 69 6f 57 72 69 74 65 28  err,"\nBioWrite(
04e0: 30 78 25 78 2c 20 3c 62 75 66 3e 2c 20 25 64 29  0x%x, <buf>, %d)
04f0: 20 5b 30 78 25 78 5d 22 2c 20 62 69 6f 2c 20 62   [0x%x]", bio, b
0500: 75 66 4c 65 6e 2c 20 63 68 61 6e 29 3b 0a 0a 20  ufLen, chan);.. 
0510: 20 20 20 72 65 74 20 3d 20 54 63 6c 5f 57 72 69     ret = Tcl_Wri
0520: 74 65 28 20 63 68 61 6e 2c 20 62 75 66 2c 20 62  te( chan, buf, b
0530: 75 66 4c 65 6e 29 3b 0a 0a 20 20 20 20 64 70 72  ufLen);..    dpr
0540: 69 6e 74 66 28 73 74 64 65 72 72 2c 22 5c 6e 5b  intf(stderr,"\n[
0550: 30 78 25 78 5d 20 42 69 6f 57 72 69 74 65 28 25  0x%x] BioWrite(%
0560: 64 29 20 2d 3e 20 25 64 20 5b 25 64 2e 25 64 5d  d) -> %d [%d.%d]
0570: 22 2c 20 63 68 61 6e 2c 20 62 75 66 4c 65 6e 2c  ", chan, bufLen,
0580: 20 72 65 74 2c 0a 09 09 54 63 6c 5f 45 6f 66 28   ret,...Tcl_Eof(
0590: 20 63 68 61 6e 29 2c 20 54 63 6c 5f 47 65 74 45   chan), Tcl_GetE
05a0: 72 72 6e 6f 28 29 29 3b 0a 0a 20 20 20 20 42 49  rrno());..    BI
05b0: 4f 5f 63 6c 65 61 72 5f 66 6c 61 67 73 28 62 69  O_clear_flags(bi
05c0: 6f 2c 20 42 49 4f 5f 46 4c 41 47 53 5f 57 52 49  o, BIO_FLAGS_WRI
05d0: 54 45 7c 42 49 4f 5f 46 4c 41 47 53 5f 53 48 4f  TE|BIO_FLAGS_SHO
05e0: 55 4c 44 5f 52 45 54 52 59 29 3b 0a 0a 20 20 20  ULD_RETRY);..   
05f0: 20 69 66 20 28 72 65 74 20 3d 3d 20 30 29 20 7b   if (ret == 0) {
0600: 0a 09 69 66 20 28 21 54 63 6c 5f 45 6f 66 28 20  ..if (!Tcl_Eof( 
0610: 63 68 61 6e 29 29 20 7b 0a 09 20 20 20 20 42 49  chan)) {..    BI
0620: 4f 5f 73 65 74 5f 72 65 74 72 79 5f 77 72 69 74  O_set_retry_writ
0630: 65 28 62 69 6f 29 3b 0a 09 20 20 20 20 72 65 74  e(bio);..    ret
0640: 20 3d 20 2d 31 3b 0a 09 7d 0a 20 20 20 20 7d 0a   = -1;..}.    }.
0650: 20 20 20 20 69 66 20 28 42 49 4f 5f 73 68 6f 75      if (BIO_shou
0660: 6c 64 5f 72 65 61 64 28 62 69 6f 29 29 0a 09 42  ld_read(bio))..B
0670: 49 4f 5f 73 65 74 5f 72 65 74 72 79 5f 72 65 61  IO_set_retry_rea
0680: 64 28 62 69 6f 29 3b 0a 20 20 20 20 72 65 74 75  d(bio);.    retu
0690: 72 6e 20 72 65 74 3b 0a 7d 0a 0a 73 74 61 74 69  rn ret;.}..stati
06a0: 63 20 69 6e 74 0a 42 69 6f 52 65 61 64 20 28 62  c int.BioRead (b
06b0: 69 6f 2c 20 62 75 66 2c 20 62 75 66 4c 65 6e 29  io, buf, bufLen)
06c0: 0a 20 20 20 20 42 49 4f 20 2a 62 69 6f 3b 0a 20  .    BIO *bio;. 
06d0: 20 20 20 63 68 61 72 20 2a 62 75 66 3b 0a 20 20     char *buf;.  
06e0: 20 20 69 6e 74 20 62 75 66 4c 65 6e 3b 0a 7b 0a    int bufLen;.{.
06f0: 20 20 20 20 54 63 6c 5f 43 68 61 6e 6e 65 6c 20      Tcl_Channel 
0700: 63 68 61 6e 20 3d 20 54 6c 73 5f 47 65 74 50 61  chan = Tls_GetPa
0710: 72 65 6e 74 28 28 53 74 61 74 65 2a 29 62 69 6f  rent((State*)bio
0720: 2d 3e 70 74 72 29 3b 0a 20 20 20 20 69 6e 74 20  ->ptr);.    int 
0730: 72 65 74 20 3d 20 30 3b 0a 0a 20 20 20 20 64 70  ret = 0;..    dp
0740: 72 69 6e 74 66 28 73 74 64 65 72 72 2c 22 5c 6e  rintf(stderr,"\n
0750: 42 69 6f 52 65 61 64 28 30 78 25 78 2c 20 3c 62  BioRead(0x%x, <b
0760: 75 66 3e 2c 20 25 64 29 20 5b 30 78 25 78 5d 22  uf>, %d) [0x%x]"
0770: 2c 20 62 69 6f 2c 20 62 75 66 4c 65 6e 2c 20 63  , bio, bufLen, c
0780: 68 61 6e 29 3b 0a 0a 20 20 20 20 69 66 20 28 62  han);..    if (b
0790: 75 66 20 3d 3d 20 4e 55 4c 4c 29 20 72 65 74 75  uf == NULL) retu
07a0: 72 6e 20 30 3b 0a 0a 20 20 20 20 72 65 74 20 3d  rn 0;..    ret =
07b0: 20 54 63 6c 5f 52 65 61 64 28 20 63 68 61 6e 2c   Tcl_Read( chan,
07c0: 20 62 75 66 2c 20 62 75 66 4c 65 6e 29 3b 0a 0a   buf, bufLen);..
07d0: 20 20 20 20 64 70 72 69 6e 74 66 28 73 74 64 65      dprintf(stde
07e0: 72 72 2c 22 5c 6e 5b 30 78 25 78 5d 20 42 69 6f  rr,"\n[0x%x] Bio
07f0: 52 65 61 64 28 25 64 29 20 2d 3e 20 25 64 20 5b  Read(%d) -> %d [
0800: 25 64 2e 25 64 5d 22 2c 20 63 68 61 6e 2c 20 62  %d.%d]", chan, b
0810: 75 66 4c 65 6e 2c 20 72 65 74 2c 0a 09 54 63 6c  ufLen, ret,..Tcl
0820: 5f 45 6f 66 28 63 68 61 6e 29 2c 20 54 63 6c 5f  _Eof(chan), Tcl_
0830: 47 65 74 45 72 72 6e 6f 28 29 29 3b 0a 0a 20 20  GetErrno());..  
0840: 20 20 42 49 4f 5f 63 6c 65 61 72 5f 66 6c 61 67    BIO_clear_flag
0850: 73 28 62 69 6f 2c 20 42 49 4f 5f 46 4c 41 47 53  s(bio, BIO_FLAGS
0860: 5f 52 45 41 44 7c 42 49 4f 5f 46 4c 41 47 53 5f  _READ|BIO_FLAGS_
0870: 53 48 4f 55 4c 44 5f 52 45 54 52 59 29 3b 0a 0a  SHOULD_RETRY);..
0880: 20 20 20 20 69 66 20 28 72 65 74 20 3d 3d 20 30      if (ret == 0
0890: 29 20 7b 0a 09 69 66 20 28 21 54 63 6c 5f 45 6f  ) {..if (!Tcl_Eo
08a0: 66 28 20 63 68 61 6e 29 29 20 7b 0a 09 20 20 20  f( chan)) {..   
08b0: 20 42 49 4f 5f 73 65 74 5f 72 65 74 72 79 5f 72   BIO_set_retry_r
08c0: 65 61 64 28 62 69 6f 29 3b 0a 09 20 20 20 20 72  ead(bio);..    r
08d0: 65 74 20 3d 20 2d 31 3b 0a 09 7d 0a 20 20 20 20  et = -1;..}.    
08e0: 7d 0a 20 20 20 20 69 66 20 28 42 49 4f 5f 73 68  }.    if (BIO_sh
08f0: 6f 75 6c 64 5f 77 72 69 74 65 28 62 69 6f 29 29  ould_write(bio))
0900: 0a 09 42 49 4f 5f 73 65 74 5f 72 65 74 72 79 5f  ..BIO_set_retry_
0910: 77 72 69 74 65 28 62 69 6f 29 3b 0a 20 20 20 20  write(bio);.    
0920: 72 65 74 75 72 6e 20 72 65 74 3b 0a 7d 0a 0a 73  return ret;.}..s
0930: 74 61 74 69 63 20 69 6e 74 0a 42 69 6f 50 75 74  tatic int.BioPut
0940: 73 09 28 62 69 6f 2c 20 73 74 72 29 0a 20 20 20  s.(bio, str).   
0950: 20 42 49 4f 20 2a 62 69 6f 3b 0a 20 20 20 20 63   BIO *bio;.    c
0960: 68 61 72 20 2a 73 74 72 3b 0a 7b 0a 20 20 20 20  har *str;.{.    
0970: 72 65 74 75 72 6e 20 42 69 6f 57 72 69 74 65 28  return BioWrite(
0980: 20 62 69 6f 2c 20 73 74 72 2c 20 73 74 72 6c 65   bio, str, strle
0990: 6e 28 73 74 72 29 29 3b 0a 7d 0a 0a 73 74 61 74  n(str));.}..stat
09a0: 69 63 20 6c 6f 6e 67 0a 42 69 6f 43 74 72 6c 09  ic long.BioCtrl.
09b0: 28 62 69 6f 2c 20 63 6d 64 2c 20 6e 75 6d 2c 20  (bio, cmd, num, 
09c0: 70 74 72 29 0a 20 20 20 20 42 49 4f 20 2a 62 69  ptr).    BIO *bi
09d0: 6f 3b 0a 20 20 20 20 69 6e 74 20 63 6d 64 3b 0a  o;.    int cmd;.
09e0: 20 20 20 20 6c 6f 6e 67 20 6e 75 6d 3b 0a 20 20      long num;.  
09f0: 20 20 63 68 61 72 20 2a 70 74 72 3b 0a 7b 0a 20    char *ptr;.{. 
0a00: 20 20 20 54 63 6c 5f 43 68 61 6e 6e 65 6c 20 63     Tcl_Channel c
0a10: 68 61 6e 20 3d 20 54 6c 73 5f 47 65 74 50 61 72  han = Tls_GetPar
0a20: 65 6e 74 28 28 53 74 61 74 65 2a 29 62 69 6f 2d  ent((State*)bio-
0a30: 3e 70 74 72 29 3b 0a 20 20 20 20 6c 6f 6e 67 20  >ptr);.    long 
0a40: 72 65 74 20 3d 20 31 3b 0a 20 20 20 20 69 6e 74  ret = 1;.    int
0a50: 20 2a 69 70 3b 0a 0a 20 20 20 20 64 70 72 69 6e   *ip;..    dprin
0a60: 74 66 28 73 74 64 65 72 72 2c 22 5c 6e 42 69 6f  tf(stderr,"\nBio
0a70: 43 74 72 6c 28 30 78 25 78 2c 20 30 78 25 78 2c  Ctrl(0x%x, 0x%x,
0a80: 20 30 78 25 78 2c 20 30 78 25 78 29 22 2c 20 62   0x%x, 0x%x)", b
0a90: 69 6f 2c 20 63 6d 64 2c 20 6e 75 6d 2c 20 70 74  io, cmd, num, pt
0aa0: 72 29 3b 0a 0a 20 20 20 20 73 77 69 74 63 68 20  r);..    switch 
0ab0: 28 63 6d 64 29 20 7b 0a 20 20 20 20 63 61 73 65  (cmd) {.    case
0ac0: 20 42 49 4f 5f 43 54 52 4c 5f 52 45 53 45 54 3a   BIO_CTRL_RESET:
0ad0: 0a 09 6e 75 6d 20 3d 20 30 3b 0a 20 20 20 20 63  ..num = 0;.    c
0ae0: 61 73 65 20 42 49 4f 5f 43 5f 46 49 4c 45 5f 53  ase BIO_C_FILE_S
0af0: 45 45 4b 3a 0a 20 20 20 20 63 61 73 65 20 42 49  EEK:.    case BI
0b00: 4f 5f 43 5f 46 49 4c 45 5f 54 45 4c 4c 3a 0a 09  O_C_FILE_TELL:..
0b10: 72 65 74 20 3d 20 30 3b 0a 09 62 72 65 61 6b 3b  ret = 0;..break;
0b20: 0a 20 20 20 20 63 61 73 65 20 42 49 4f 5f 43 54  .    case BIO_CT
0b30: 52 4c 5f 49 4e 46 4f 3a 0a 09 72 65 74 20 3d 20  RL_INFO:..ret = 
0b40: 31 3b 0a 09 62 72 65 61 6b 3b 0a 20 20 20 20 63  1;..break;.    c
0b50: 61 73 65 20 42 49 4f 5f 43 5f 53 45 54 5f 46 44  ase BIO_C_SET_FD
0b60: 3a 0a 09 42 69 6f 46 72 65 65 28 62 69 6f 29 3b  :..BioFree(bio);
0b70: 0a 09 2f 2a 20 53 65 74 73 20 53 74 61 74 65 2a  ../* Sets State*
0b80: 20 2a 2f 0a 09 62 69 6f 2d 3e 70 74 72 20 3d 20   */..bio->ptr = 
0b90: 2a 28 28 63 68 61 72 20 2a 2a 29 70 74 72 29 3b  *((char **)ptr);
0ba0: 0a 09 62 69 6f 2d 3e 73 68 75 74 64 6f 77 6e 20  ..bio->shutdown 
0bb0: 3d 20 28 69 6e 74 29 6e 75 6d 3b 0a 09 62 69 6f  = (int)num;..bio
0bc0: 2d 3e 69 6e 69 74 20 3d 20 31 3b 0a 09 62 72 65  ->init = 1;..bre
0bd0: 61 6b 3b 0a 20 20 20 20 63 61 73 65 20 42 49 4f  ak;.    case BIO
0be0: 5f 43 5f 47 45 54 5f 46 44 3a 0a 09 69 66 20 28  _C_GET_FD:..if (
0bf0: 62 69 6f 2d 3e 69 6e 69 74 29 20 7b 0a 09 20 20  bio->init) {..  
0c00: 20 20 69 70 3d 28 69 6e 74 20 2a 29 70 74 72 3b    ip=(int *)ptr;
0c10: 0a 09 20 20 20 20 69 66 20 28 69 70 20 21 3d 20  ..    if (ip != 
0c20: 4e 55 4c 4c 29 20 2a 69 70 3d 62 69 6f 2d 3e 6e  NULL) *ip=bio->n
0c30: 75 6d 3b 0a 09 09 72 65 74 3d 62 69 6f 2d 3e 6e  um;...ret=bio->n
0c40: 75 6d 3b 0a 09 7d 20 65 6c 73 65 20 7b 0a 09 20  um;..} else {.. 
0c50: 20 20 20 72 65 74 3d 20 2d 31 3b 0a 09 7d 0a 09     ret= -1;..}..
0c60: 62 72 65 61 6b 3b 0a 20 20 20 20 63 61 73 65 20  break;.    case 
0c70: 42 49 4f 5f 43 54 52 4c 5f 47 45 54 5f 43 4c 4f  BIO_CTRL_GET_CLO
0c80: 53 45 3a 0a 09 72 65 74 3d 62 69 6f 2d 3e 73 68  SE:..ret=bio->sh
0c90: 75 74 64 6f 77 6e 3b 0a 09 62 72 65 61 6b 3b 0a  utdown;..break;.
0ca0: 20 20 20 20 63 61 73 65 20 42 49 4f 5f 43 54 52      case BIO_CTR
0cb0: 4c 5f 53 45 54 5f 43 4c 4f 53 45 3a 0a 09 62 69  L_SET_CLOSE:..bi
0cc0: 6f 2d 3e 73 68 75 74 64 6f 77 6e 3d 28 69 6e 74  o->shutdown=(int
0cd0: 29 6e 75 6d 3b 0a 09 62 72 65 61 6b 3b 0a 20 20  )num;..break;.  
0ce0: 20 20 63 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f    case BIO_CTRL_
0cf0: 45 4f 46 3a 0a 09 64 70 72 69 6e 74 66 28 73 74  EOF:..dprintf(st
0d00: 64 65 72 72 2c 20 22 42 49 4f 5f 43 54 52 4c 5f  derr, "BIO_CTRL_
0d10: 45 4f 46 5c 6e 22 29 3b 0a 09 72 65 74 20 3d 20  EOF\n");..ret = 
0d20: 54 63 6c 5f 45 6f 66 28 20 63 68 61 6e 29 3b 0a  Tcl_Eof( chan);.
0d30: 09 62 72 65 61 6b 3b 0a 20 20 20 20 63 61 73 65  .break;.    case
0d40: 20 42 49 4f 5f 43 54 52 4c 5f 50 45 4e 44 49 4e   BIO_CTRL_PENDIN
0d50: 47 3a 0a 09 69 66 20 28 54 63 6c 5f 49 6e 70 75  G:..if (Tcl_Inpu
0d60: 74 42 75 66 66 65 72 65 64 28 63 68 61 6e 29 29  tBuffered(chan))
0d70: 0a 09 20 20 20 20 72 65 74 20 3d 20 31 3b 0a 09  ..    ret = 1;..
0d80: 65 6c 73 65 0a 09 20 20 20 20 72 65 74 20 3d 20  else..    ret = 
0d90: 30 3b 0a 09 64 70 72 69 6e 74 66 28 73 74 64 65  0;..dprintf(stde
0da0: 72 72 2c 20 22 42 49 4f 5f 43 54 52 4c 5f 50 45  rr, "BIO_CTRL_PE
0db0: 4e 44 49 4e 47 28 25 64 29 5c 6e 22 2c 20 72 65  NDING(%d)\n", re
0dc0: 74 29 3b 0a 09 62 72 65 61 6b 3b 0a 20 20 20 20  t);..break;.    
0dd0: 63 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f 57 50  case BIO_CTRL_WP
0de0: 45 4e 44 49 4e 47 3a 0a 09 72 65 74 3d 30 3b 0a  ENDING:..ret=0;.
0df0: 09 62 72 65 61 6b 3b 0a 20 20 20 20 63 61 73 65  .break;.    case
0e00: 20 42 49 4f 5f 43 54 52 4c 5f 44 55 50 3a 0a 09   BIO_CTRL_DUP:..
0e10: 62 72 65 61 6b 3b 0a 20 20 20 20 63 61 73 65 20  break;.    case 
0e20: 42 49 4f 5f 43 54 52 4c 5f 46 4c 55 53 48 3a 0a  BIO_CTRL_FLUSH:.
0e30: 09 64 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c  .dprintf(stderr,
0e40: 20 22 42 49 4f 5f 43 54 52 4c 5f 46 4c 55 53 48   "BIO_CTRL_FLUSH
0e50: 5c 6e 22 29 3b 0a 09 69 66 20 28 54 63 6c 5f 46  \n");..if (Tcl_F
0e60: 6c 75 73 68 28 20 63 68 61 6e 29 20 3d 3d 20 54  lush( chan) == T
0e70: 43 4c 5f 4f 4b 29 0a 09 20 20 20 20 72 65 74 3d  CL_OK)..    ret=
0e80: 31 3b 0a 09 65 6c 73 65 0a 09 20 20 20 20 72 65  1;..else..    re
0e90: 74 3d 2d 31 3b 0a 09 62 72 65 61 6b 3b 0a 20 20  t=-1;..break;.  
0ea0: 20 20 64 65 66 61 75 6c 74 3a 0a 09 72 65 74 3d    default:..ret=
0eb0: 30 3b 0a 09 62 72 65 61 6b 3b 0a 20 20 20 20 7d  0;..break;.    }
0ec0: 0a 20 20 20 20 72 65 74 75 72 6e 28 72 65 74 29  .    return(ret)
0ed0: 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 0a  ;.}..static int.
0ee0: 42 69 6f 4e 65 77 09 28 62 69 6f 29 0a 20 20 20  BioNew.(bio).   
0ef0: 20 42 49 4f 20 2a 62 69 6f 3b 0a 7b 0a 20 20 20   BIO *bio;.{.   
0f00: 20 62 69 6f 2d 3e 69 6e 69 74 20 3d 20 30 3b 0a   bio->init = 0;.
0f10: 20 20 20 20 62 69 6f 2d 3e 6e 75 6d 20 3d 20 30      bio->num = 0
0f20: 3b 0a 20 20 20 20 62 69 6f 2d 3e 70 74 72 20 3d  ;.    bio->ptr =
0f30: 20 4e 55 4c 4c 3b 0a 20 20 20 20 62 69 6f 2d 3e   NULL;.    bio->
0f40: 66 6c 61 67 73 20 3d 20 30 3b 0a 0a 20 20 20 20  flags = 0;..    
0f50: 72 65 74 75 72 6e 20 31 3b 0a 7d 0a 0a 73 74 61  return 1;.}..sta
0f60: 74 69 63 20 69 6e 74 0a 42 69 6f 46 72 65 65 09  tic int.BioFree.
0f70: 28 62 69 6f 29 0a 20 20 20 20 42 49 4f 20 2a 62  (bio).    BIO *b
0f80: 69 6f 3b 0a 7b 0a 20 20 20 20 69 66 20 28 62 69  io;.{.    if (bi
0f90: 6f 20 3d 3d 20 4e 55 4c 4c 29 0a 09 72 65 74 75  o == NULL)..retu
0fa0: 72 6e 20 30 3b 0a 0a 20 20 20 20 69 66 20 28 62  rn 0;..    if (b
0fb0: 69 6f 2d 3e 73 68 75 74 64 6f 77 6e 29 20 7b 0a  io->shutdown) {.
0fc0: 09 69 66 20 28 62 69 6f 2d 3e 69 6e 69 74 29 20  .if (bio->init) 
0fd0: 7b 0a 09 20 20 20 20 2f 2a 73 68 75 74 64 6f 77  {..    /*shutdow
0fe0: 6e 28 62 69 6f 2d 3e 6e 75 6d 2c 20 32 29 20 2a  n(bio->num, 2) *
0ff0: 2f 0a 09 20 20 20 20 2f 2a 63 6c 6f 73 65 73 6f  /..    /*closeso
1000: 63 6b 65 74 28 62 69 6f 2d 3e 6e 75 6d 29 20 2a  cket(bio->num) *
1010: 2f 0a 09 7d 0a 09 62 69 6f 2d 3e 69 6e 69 74 20  /..}..bio->init 
1020: 3d 20 30 3b 0a 09 62 69 6f 2d 3e 66 6c 61 67 73  = 0;..bio->flags
1030: 20 3d 20 30 3b 0a 09 62 69 6f 2d 3e 6e 75 6d 20   = 0;..bio->num 
1040: 3d 20 30 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72  = 0;.    }.    r
1050: 65 74 75 72 6e 20 31 3b 0a 7d 0a                 eturn 1;.}.