Hex Artifact Content

Artifact b685c38f1104cc06f3ea9c09dd4329e19d56685b58944c9b2db3d89e2cb92cfd:


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 50 72 6f 76 69 64 65 73 20 42 49 4f  . * Provides BIO
0050: 20 6c 61 79 65 72 20 74 6f 20 69 6e 74 65 72 66   layer to interf
0060: 61 63 65 20 6f 70 65 6e 73 73 6c 20 74 6f 20 54  ace openssl to T
0070: 63 6c 2e 0a 20 2a 2f 0a 0a 23 69 6e 63 6c 75 64  cl.. */..#includ
0080: 65 20 22 74 6c 73 49 6e 74 2e 68 22 0a 0a 23 69  e "tlsInt.h"..#i
0090: 66 64 65 66 20 54 43 4c 54 4c 53 5f 4f 50 45 4e  fdef TCLTLS_OPEN
00a0: 53 53 4c 5f 50 52 45 5f 31 5f 31 5f 41 50 49 0a  SSL_PRE_1_1_API.
00b0: 23 64 65 66 69 6e 65 20 42 49 4f 5f 67 65 74 5f  #define BIO_get_
00c0: 64 61 74 61 28 62 69 6f 29 20 20 20 20 20 20 20  data(bio)       
00d0: 20 20 20 20 20 20 20 20 20 28 28 62 69 6f 29 2d           ((bio)-
00e0: 3e 70 74 72 29 0a 23 64 65 66 69 6e 65 20 42 49  >ptr).#define BI
00f0: 4f 5f 67 65 74 5f 69 6e 69 74 28 62 69 6f 29 20  O_get_init(bio) 
0100: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 28                 (
0110: 28 62 69 6f 29 2d 3e 69 6e 69 74 29 0a 23 64 65  (bio)->init).#de
0120: 66 69 6e 65 20 42 49 4f 5f 67 65 74 5f 73 68 75  fine BIO_get_shu
0130: 74 64 6f 77 6e 28 62 69 6f 29 20 20 20 20 20 20  tdown(bio)      
0140: 20 20 20 20 20 20 28 28 62 69 6f 29 2d 3e 73 68        ((bio)->sh
0150: 75 74 64 6f 77 6e 29 0a 23 64 65 66 69 6e 65 20  utdown).#define 
0160: 42 49 4f 5f 73 65 74 5f 64 61 74 61 28 62 69 6f  BIO_set_data(bio
0170: 2c 20 76 61 6c 29 20 20 20 20 20 20 20 20 20 20  , val)          
0180: 20 28 62 69 6f 29 2d 3e 70 74 72 20 3d 20 28 76   (bio)->ptr = (v
0190: 61 6c 29 0a 23 64 65 66 69 6e 65 20 42 49 4f 5f  al).#define BIO_
01a0: 73 65 74 5f 69 6e 69 74 28 62 69 6f 2c 20 76 61  set_init(bio, va
01b0: 6c 29 20 20 20 20 20 20 20 20 20 20 20 28 62 69  l)           (bi
01c0: 6f 29 2d 3e 69 6e 69 74 20 3d 20 28 76 61 6c 29  o)->init = (val)
01d0: 0a 23 64 65 66 69 6e 65 20 42 49 4f 5f 73 65 74  .#define BIO_set
01e0: 5f 73 68 75 74 64 6f 77 6e 28 62 69 6f 2c 20 76  _shutdown(bio, v
01f0: 61 6c 29 20 20 20 20 20 20 20 28 62 69 6f 29 2d  al)       (bio)-
0200: 3e 73 68 75 74 64 6f 77 6e 20 3d 20 28 76 61 6c  >shutdown = (val
0210: 29 0a 0a 2f 2a 20 58 58 58 3a 20 54 68 69 73 20  )../* XXX: This 
0220: 61 73 73 75 6d 65 73 20 74 68 65 20 76 61 72 69  assumes the vari
0230: 61 62 6c 65 20 62 65 69 6e 67 20 61 73 73 69 67  able being assig
0240: 6e 65 64 20 74 6f 20 69 73 20 42 69 6f 4d 65 74  ned to is BioMet
0250: 68 6f 64 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20  hods */.#define 
0260: 42 49 4f 5f 6d 65 74 68 5f 6e 65 77 28 74 79 70  BIO_meth_new(typ
0270: 65 5f 2c 20 6e 61 6d 65 5f 29 20 20 20 20 20 20  e_, name_)      
0280: 20 28 42 49 4f 5f 4d 45 54 48 4f 44 20 2a 29 54   (BIO_METHOD *)T
0290: 63 6c 5f 41 6c 6c 6f 63 28 73 69 7a 65 6f 66 28  cl_Alloc(sizeof(
02a0: 42 49 4f 5f 4d 45 54 48 4f 44 29 29 3b 20 5c 0a  BIO_METHOD)); \.
02b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
02c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
02d0: 20 20 20 20 20 20 20 20 20 6d 65 6d 73 65 74 28           memset(
02e0: 42 69 6f 4d 65 74 68 6f 64 73 2c 20 30 2c 20 73  BioMethods, 0, s
02f0: 69 7a 65 6f 66 28 42 49 4f 5f 4d 45 54 48 4f 44  izeof(BIO_METHOD
0300: 29 29 3b 20 5c 0a 20 20 20 20 20 20 20 20 20 20  )); \.          
0310: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0320: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 42                 B
0330: 69 6f 4d 65 74 68 6f 64 73 2d 3e 74 79 70 65 20  ioMethods->type 
0340: 3d 20 74 79 70 65 5f 3b 20 5c 0a 20 20 20 20 20  = type_; \.     
0350: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0360: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0370: 20 20 20 20 42 69 6f 4d 65 74 68 6f 64 73 2d 3e      BioMethods->
0380: 6e 61 6d 65 20 3d 20 6e 61 6d 65 5f 3b 0a 23 64  name = name_;.#d
0390: 65 66 69 6e 65 20 42 49 4f 5f 6d 65 74 68 5f 73  efine BIO_meth_s
03a0: 65 74 5f 77 72 69 74 65 28 62 69 6f 2c 20 76 61  et_write(bio, va
03b0: 6c 29 20 20 20 20 20 28 62 69 6f 29 2d 3e 62 77  l)     (bio)->bw
03c0: 72 69 74 65 20 3d 20 76 61 6c 3b 0a 23 64 65 66  rite = val;.#def
03d0: 69 6e 65 20 42 49 4f 5f 6d 65 74 68 5f 73 65 74  ine BIO_meth_set
03e0: 5f 72 65 61 64 28 62 69 6f 2c 20 76 61 6c 29 20  _read(bio, val) 
03f0: 20 20 20 20 20 28 62 69 6f 29 2d 3e 62 72 65 61       (bio)->brea
0400: 64 20 3d 20 76 61 6c 3b 0a 23 64 65 66 69 6e 65  d = val;.#define
0410: 20 42 49 4f 5f 6d 65 74 68 5f 73 65 74 5f 70 75   BIO_meth_set_pu
0420: 74 73 28 62 69 6f 2c 20 76 61 6c 29 20 20 20 20  ts(bio, val)    
0430: 20 20 28 62 69 6f 29 2d 3e 62 70 75 74 73 20 3d    (bio)->bputs =
0440: 20 76 61 6c 3b 0a 23 64 65 66 69 6e 65 20 42 49   val;.#define BI
0450: 4f 5f 6d 65 74 68 5f 73 65 74 5f 63 74 72 6c 28  O_meth_set_ctrl(
0460: 62 69 6f 2c 20 76 61 6c 29 20 20 20 20 20 20 28  bio, val)      (
0470: 62 69 6f 29 2d 3e 63 74 72 6c 20 3d 20 76 61 6c  bio)->ctrl = val
0480: 3b 0a 23 64 65 66 69 6e 65 20 42 49 4f 5f 6d 65  ;.#define BIO_me
0490: 74 68 5f 73 65 74 5f 63 72 65 61 74 65 28 62 69  th_set_create(bi
04a0: 6f 2c 20 76 61 6c 29 20 20 20 20 28 62 69 6f 29  o, val)    (bio)
04b0: 2d 3e 63 72 65 61 74 65 20 3d 20 76 61 6c 3b 0a  ->create = val;.
04c0: 23 64 65 66 69 6e 65 20 42 49 4f 5f 6d 65 74 68  #define BIO_meth
04d0: 5f 73 65 74 5f 64 65 73 74 72 6f 79 28 62 69 6f  _set_destroy(bio
04e0: 2c 20 76 61 6c 29 20 20 20 28 62 69 6f 29 2d 3e  , val)   (bio)->
04f0: 64 65 73 74 72 6f 79 20 3d 20 76 61 6c 3b 0a 23  destroy = val;.#
0500: 65 6e 64 69 66 0a 0a 2f 2a 0a 20 2a 20 46 6f 72  endif../*. * For
0510: 77 61 72 64 20 64 65 63 6c 61 72 61 74 69 6f 6e  ward declaration
0520: 73 0a 20 2a 2f 0a 0a 73 74 61 74 69 63 20 69 6e  s. */..static in
0530: 74 20 42 69 6f 57 72 69 74 65 20 28 42 49 4f 20  t BioWrite (BIO 
0540: 2a 68 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a  *h, const char *
0550: 62 75 66 2c 20 69 6e 74 20 6e 75 6d 29 3b 0a 73  buf, int num);.s
0560: 74 61 74 69 63 20 69 6e 74 20 42 69 6f 52 65 61  tatic int BioRea
0570: 64 20 20 28 42 49 4f 20 2a 68 2c 20 63 68 61 72  d  (BIO *h, char
0580: 20 2a 62 75 66 2c 20 69 6e 74 20 6e 75 6d 29 3b   *buf, int num);
0590: 0a 73 74 61 74 69 63 20 69 6e 74 20 42 69 6f 50  .static int BioP
05a0: 75 74 73 20 20 28 42 49 4f 20 2a 68 2c 20 63 6f  uts  (BIO *h, co
05b0: 6e 73 74 20 63 68 61 72 20 2a 73 74 72 29 3b 0a  nst char *str);.
05c0: 73 74 61 74 69 63 20 6c 6f 6e 67 20 42 69 6f 43  static long BioC
05d0: 74 72 6c 20 28 42 49 4f 20 2a 68 2c 20 69 6e 74  trl (BIO *h, int
05e0: 20 63 6d 64 2c 20 6c 6f 6e 67 20 61 72 67 31 2c   cmd, long arg1,
05f0: 20 76 6f 69 64 20 2a 70 74 72 29 3b 0a 73 74 61   void *ptr);.sta
0600: 74 69 63 20 69 6e 74 20 42 69 6f 4e 65 77 20 20  tic int BioNew  
0610: 20 28 42 49 4f 20 2a 68 29 3b 0a 73 74 61 74 69   (BIO *h);.stati
0620: 63 20 69 6e 74 20 42 69 6f 46 72 65 65 20 20 28  c int BioFree  (
0630: 42 49 4f 20 2a 68 29 3b 0a 0a 42 49 4f 20 2a 42  BIO *h);..BIO *B
0640: 49 4f 5f 6e 65 77 5f 74 63 6c 28 53 74 61 74 65  IO_new_tcl(State
0650: 20 2a 73 74 61 74 65 50 74 72 2c 20 69 6e 74 20   *statePtr, int 
0660: 66 6c 61 67 73 29 20 7b 0a 09 42 49 4f 20 2a 62  flags) {..BIO *b
0670: 69 6f 3b 0a 09 73 74 61 74 69 63 20 42 49 4f 5f  io;..static BIO_
0680: 4d 45 54 48 4f 44 20 2a 42 69 6f 4d 65 74 68 6f  METHOD *BioMetho
0690: 64 73 20 3d 20 4e 55 4c 4c 3b 0a 23 69 66 64 65  ds = NULL;.#ifde
06a0: 66 20 54 43 4c 54 4c 53 5f 53 53 4c 5f 55 53 45  f TCLTLS_SSL_USE
06b0: 5f 46 41 53 54 50 41 54 48 0a 09 54 63 6c 5f 43  _FASTPATH..Tcl_C
06c0: 68 61 6e 6e 65 6c 20 70 61 72 65 6e 74 43 68 61  hannel parentCha
06d0: 6e 6e 65 6c 3b 0a 09 63 6f 6e 73 74 20 54 63 6c  nnel;..const Tcl
06e0: 5f 43 68 61 6e 6e 65 6c 54 79 70 65 20 2a 70 61  _ChannelType *pa
06f0: 72 65 6e 74 43 68 61 6e 6e 65 6c 54 79 70 65 3b  rentChannelType;
0700: 0a 09 76 6f 69 64 20 2a 70 61 72 65 6e 74 43 68  ..void *parentCh
0710: 61 6e 6e 65 6c 46 64 49 6e 5f 70 2c 20 2a 70 61  annelFdIn_p, *pa
0720: 72 65 6e 74 43 68 61 6e 6e 65 6c 46 64 4f 75 74  rentChannelFdOut
0730: 5f 70 3b 0a 09 69 6e 74 20 70 61 72 65 6e 74 43  _p;..int parentC
0740: 68 61 6e 6e 65 6c 46 64 49 6e 2c 20 70 61 72 65  hannelFdIn, pare
0750: 6e 74 43 68 61 6e 6e 65 6c 46 64 4f 75 74 2c 20  ntChannelFdOut, 
0760: 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c 46 64 3b  parentChannelFd;
0770: 0a 09 69 6e 74 20 76 61 6c 69 64 50 61 72 65 6e  ..int validParen
0780: 74 43 68 61 6e 6e 65 6c 46 64 3b 0a 09 69 6e 74  tChannelFd;..int
0790: 20 74 63 6c 47 65 74 43 68 61 6e 6e 65 6c 48 61   tclGetChannelHa
07a0: 6e 64 6c 65 52 65 74 3b 0a 23 65 6e 64 69 66 0a  ndleRet;.#endif.
07b0: 0a 09 64 70 72 69 6e 74 66 28 22 42 49 4f 5f 6e  ..dprintf("BIO_n
07c0: 65 77 5f 74 63 6c 28 29 20 63 61 6c 6c 65 64 22  ew_tcl() called"
07d0: 29 3b 0a 0a 09 69 66 20 28 42 69 6f 4d 65 74 68  );...if (BioMeth
07e0: 6f 64 73 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09  ods == NULL) {..
07f0: 09 42 69 6f 4d 65 74 68 6f 64 73 20 3d 20 42 49  .BioMethods = BI
0800: 4f 5f 6d 65 74 68 5f 6e 65 77 28 42 49 4f 5f 54  O_meth_new(BIO_T
0810: 59 50 45 5f 54 43 4c 2c 20 22 74 63 6c 22 29 3b  YPE_TCL, "tcl");
0820: 0a 09 09 42 49 4f 5f 6d 65 74 68 5f 73 65 74 5f  ...BIO_meth_set_
0830: 77 72 69 74 65 28 42 69 6f 4d 65 74 68 6f 64 73  write(BioMethods
0840: 2c 20 42 69 6f 57 72 69 74 65 29 3b 0a 09 09 42  , BioWrite);...B
0850: 49 4f 5f 6d 65 74 68 5f 73 65 74 5f 72 65 61 64  IO_meth_set_read
0860: 28 42 69 6f 4d 65 74 68 6f 64 73 2c 20 42 69 6f  (BioMethods, Bio
0870: 52 65 61 64 29 3b 0a 09 09 42 49 4f 5f 6d 65 74  Read);...BIO_met
0880: 68 5f 73 65 74 5f 70 75 74 73 28 42 69 6f 4d 65  h_set_puts(BioMe
0890: 74 68 6f 64 73 2c 20 42 69 6f 50 75 74 73 29 3b  thods, BioPuts);
08a0: 0a 09 09 42 49 4f 5f 6d 65 74 68 5f 73 65 74 5f  ...BIO_meth_set_
08b0: 63 74 72 6c 28 42 69 6f 4d 65 74 68 6f 64 73 2c  ctrl(BioMethods,
08c0: 20 42 69 6f 43 74 72 6c 29 3b 0a 09 09 42 49 4f   BioCtrl);...BIO
08d0: 5f 6d 65 74 68 5f 73 65 74 5f 63 72 65 61 74 65  _meth_set_create
08e0: 28 42 69 6f 4d 65 74 68 6f 64 73 2c 20 42 69 6f  (BioMethods, Bio
08f0: 4e 65 77 29 3b 0a 09 09 42 49 4f 5f 6d 65 74 68  New);...BIO_meth
0900: 5f 73 65 74 5f 64 65 73 74 72 6f 79 28 42 69 6f  _set_destroy(Bio
0910: 4d 65 74 68 6f 64 73 2c 20 42 69 6f 46 72 65 65  Methods, BioFree
0920: 29 3b 0a 09 7d 0a 0a 09 69 66 20 28 73 74 61 74  );..}...if (stat
0930: 65 50 74 72 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a  ePtr == NULL) {.
0940: 09 09 64 70 72 69 6e 74 66 28 22 41 73 6b 65 64  ..dprintf("Asked
0950: 20 74 6f 20 73 65 74 75 70 20 61 20 4e 55 4c 4c   to setup a NULL
0960: 20 73 74 61 74 65 2c 20 6a 75 73 74 20 63 72 65   state, just cre
0970: 61 74 69 6e 67 20 74 68 65 20 69 6e 69 74 69 61  ating the initia
0980: 6c 20 63 6f 6e 66 69 67 75 72 61 74 69 6f 6e 22  l configuration"
0990: 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 4e 55 4c  );....return(NUL
09a0: 4c 29 3b 0a 09 7d 0a 0a 23 69 66 64 65 66 20 54  L);..}..#ifdef T
09b0: 43 4c 54 4c 53 5f 53 53 4c 5f 55 53 45 5f 46 41  CLTLS_SSL_USE_FA
09c0: 53 54 50 41 54 48 0a 09 2f 2a 0a 09 20 2a 20 49  STPATH../*.. * I
09d0: 66 20 74 68 65 20 63 68 61 6e 6e 65 6c 20 63 61  f the channel ca
09e0: 6e 20 62 65 20 6d 61 70 70 65 64 20 62 61 63 6b  n be mapped back
09f0: 20 74 6f 20 61 20 66 69 6c 65 20 64 65 73 63 72   to a file descr
0a00: 69 70 74 6f 72 2c 20 6a 75 73 74 20 75 73 65 20  iptor, just use 
0a10: 74 68 65 20 66 69 6c 65 20 64 65 73 63 72 69 70  the file descrip
0a20: 74 6f 72 0a 09 20 2a 20 77 69 74 68 20 74 68 65  tor.. * with the
0a30: 20 53 53 4c 20 6c 69 62 72 61 72 79 20 73 69 6e   SSL library sin
0a40: 63 65 20 69 74 20 77 69 6c 6c 20 6c 69 6b 65 6c  ce it will likel
0a50: 79 20 62 65 20 6f 70 74 69 6d 69 7a 65 64 20 66  y be optimized f
0a60: 6f 72 20 74 68 69 73 2e 0a 09 20 2a 2f 0a 09 70  or this... */..p
0a70: 61 72 65 6e 74 43 68 61 6e 6e 65 6c 20 3d 20 54  arentChannel = T
0a80: 6c 73 5f 47 65 74 50 61 72 65 6e 74 28 73 74 61  ls_GetParent(sta
0a90: 74 65 50 74 72 2c 20 30 29 3b 0a 09 70 61 72 65  tePtr, 0);..pare
0aa0: 6e 74 43 68 61 6e 6e 65 6c 54 79 70 65 20 3d 20  ntChannelType = 
0ab0: 54 63 6c 5f 47 65 74 43 68 61 6e 6e 65 6c 54 79  Tcl_GetChannelTy
0ac0: 70 65 28 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c  pe(parentChannel
0ad0: 29 3b 0a 0a 09 76 61 6c 69 64 50 61 72 65 6e 74  );...validParent
0ae0: 43 68 61 6e 6e 65 6c 46 64 20 3d 20 30 3b 0a 09  ChannelFd = 0;..
0af0: 69 66 20 28 73 74 72 63 6d 70 28 70 61 72 65 6e  if (strcmp(paren
0b00: 74 43 68 61 6e 6e 65 6c 54 79 70 65 2d 3e 74 79  tChannelType->ty
0b10: 70 65 4e 61 6d 65 2c 20 22 74 63 70 22 29 20 3d  peName, "tcp") =
0b20: 3d 20 30 29 20 7b 0a 09 09 74 63 6c 47 65 74 43  = 0) {...tclGetC
0b30: 68 61 6e 6e 65 6c 48 61 6e 64 6c 65 52 65 74 20  hannelHandleRet 
0b40: 3d 20 54 63 6c 5f 47 65 74 43 68 61 6e 6e 65 6c  = Tcl_GetChannel
0b50: 48 61 6e 64 6c 65 28 70 61 72 65 6e 74 43 68 61  Handle(parentCha
0b60: 6e 6e 65 6c 2c 20 54 43 4c 5f 52 45 41 44 41 42  nnel, TCL_READAB
0b70: 4c 45 2c 20 28 43 6c 69 65 6e 74 44 61 74 61 29  LE, (ClientData)
0b80: 20 26 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c 46   &parentChannelF
0b90: 64 49 6e 5f 70 29 3b 0a 09 09 69 66 20 28 74 63  dIn_p);...if (tc
0ba0: 6c 47 65 74 43 68 61 6e 6e 65 6c 48 61 6e 64 6c  lGetChannelHandl
0bb0: 65 52 65 74 20 3d 3d 20 54 43 4c 5f 4f 4b 29 20  eRet == TCL_OK) 
0bc0: 7b 0a 09 09 09 74 63 6c 47 65 74 43 68 61 6e 6e  {....tclGetChann
0bd0: 65 6c 48 61 6e 64 6c 65 52 65 74 20 3d 20 54 63  elHandleRet = Tc
0be0: 6c 5f 47 65 74 43 68 61 6e 6e 65 6c 48 61 6e 64  l_GetChannelHand
0bf0: 6c 65 28 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c  le(parentChannel
0c00: 2c 20 54 43 4c 5f 57 52 49 54 41 42 4c 45 2c 20  , TCL_WRITABLE, 
0c10: 28 43 6c 69 65 6e 74 44 61 74 61 29 20 26 70 61  (ClientData) &pa
0c20: 72 65 6e 74 43 68 61 6e 6e 65 6c 46 64 4f 75 74  rentChannelFdOut
0c30: 5f 70 29 3b 0a 09 09 09 69 66 20 28 74 63 6c 47  _p);....if (tclG
0c40: 65 74 43 68 61 6e 6e 65 6c 48 61 6e 64 6c 65 52  etChannelHandleR
0c50: 65 74 20 3d 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a  et == TCL_OK) {.
0c60: 09 09 09 09 70 61 72 65 6e 74 43 68 61 6e 6e 65  ....parentChanne
0c70: 6c 46 64 49 6e 20 3d 20 50 54 52 32 49 4e 54 28  lFdIn = PTR2INT(
0c80: 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c 46 64 49  parentChannelFdI
0c90: 6e 5f 70 29 3b 0a 09 09 09 09 70 61 72 65 6e 74  n_p);.....parent
0ca0: 43 68 61 6e 6e 65 6c 46 64 4f 75 74 20 3d 20 50  ChannelFdOut = P
0cb0: 54 52 32 49 4e 54 28 70 61 72 65 6e 74 43 68 61  TR2INT(parentCha
0cc0: 6e 6e 65 6c 46 64 4f 75 74 5f 70 29 3b 0a 09 09  nnelFdOut_p);...
0cd0: 09 09 69 66 20 28 70 61 72 65 6e 74 43 68 61 6e  ..if (parentChan
0ce0: 6e 65 6c 46 64 49 6e 20 3d 3d 20 70 61 72 65 6e  nelFdIn == paren
0cf0: 74 43 68 61 6e 6e 65 6c 46 64 4f 75 74 29 20 7b  tChannelFdOut) {
0d00: 0a 09 09 09 09 09 70 61 72 65 6e 74 43 68 61 6e  ......parentChan
0d10: 6e 65 6c 46 64 20 3d 20 70 61 72 65 6e 74 43 68  nelFd = parentCh
0d20: 61 6e 6e 65 6c 46 64 49 6e 3b 0a 09 09 09 09 09  annelFdIn;......
0d30: 76 61 6c 69 64 50 61 72 65 6e 74 43 68 61 6e 6e  validParentChann
0d40: 65 6c 46 64 20 3d 20 31 3b 0a 09 09 09 09 7d 0a  elFd = 1;.....}.
0d50: 09 09 09 7d 0a 09 09 7d 0a 09 7d 0a 0a 09 69 66  ...}...}..}...if
0d60: 20 28 76 61 6c 69 64 50 61 72 65 6e 74 43 68 61   (validParentCha
0d70: 6e 6e 65 6c 46 64 29 20 7b 0a 09 09 64 70 72 69  nnelFd) {...dpri
0d80: 6e 74 66 28 22 57 65 20 66 6f 75 6e 64 20 61 20  ntf("We found a 
0d90: 73 68 6f 72 74 63 75 74 2c 20 74 68 69 73 20 63  shortcut, this c
0da0: 68 61 6e 6e 65 6c 20 69 73 20 62 61 63 6b 65 64  hannel is backed
0db0: 20 62 79 20 61 20 73 6f 63 6b 65 74 3a 20 25 69   by a socket: %i
0dc0: 22 2c 20 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c  ", parentChannel
0dd0: 46 64 49 6e 29 3b 0a 09 09 62 69 6f 20 3d 20 42  FdIn);...bio = B
0de0: 49 4f 5f 6e 65 77 5f 73 6f 63 6b 65 74 28 70 61  IO_new_socket(pa
0df0: 72 65 6e 74 43 68 61 6e 6e 65 6c 46 64 2c 20 66  rentChannelFd, f
0e00: 6c 61 67 73 29 3b 0a 09 09 73 74 61 74 65 50 74  lags);...statePt
0e10: 72 2d 3e 66 6c 61 67 73 20 7c 3d 20 54 4c 53 5f  r->flags |= TLS_
0e20: 54 43 4c 5f 46 41 53 54 50 41 54 48 3b 0a 09 09  TCL_FASTPATH;...
0e30: 72 65 74 75 72 6e 28 62 69 6f 29 3b 0a 09 7d 0a  return(bio);..}.
0e40: 0a 09 64 70 72 69 6e 74 66 28 22 46 61 6c 6c 69  ..dprintf("Falli
0e50: 6e 67 20 62 61 63 6b 20 74 6f 20 54 63 6c 20 49  ng back to Tcl I
0e60: 2f 4f 20 66 6f 72 20 74 68 69 73 20 63 68 61 6e  /O for this chan
0e70: 6e 65 6c 22 29 3b 0a 23 65 6e 64 69 66 0a 0a 09  nel");.#endif...
0e80: 62 69 6f 20 3d 20 42 49 4f 5f 6e 65 77 28 42 69  bio = BIO_new(Bi
0e90: 6f 4d 65 74 68 6f 64 73 29 3b 0a 09 42 49 4f 5f  oMethods);..BIO_
0ea0: 73 65 74 5f 64 61 74 61 28 62 69 6f 2c 20 73 74  set_data(bio, st
0eb0: 61 74 65 50 74 72 29 3b 0a 09 42 49 4f 5f 73 65  atePtr);..BIO_se
0ec0: 74 5f 73 68 75 74 64 6f 77 6e 28 62 69 6f 2c 20  t_shutdown(bio, 
0ed0: 66 6c 61 67 73 29 3b 0a 09 42 49 4f 5f 73 65 74  flags);..BIO_set
0ee0: 5f 69 6e 69 74 28 62 69 6f 2c 20 31 29 3b 0a 0a  _init(bio, 1);..
0ef0: 09 72 65 74 75 72 6e 28 62 69 6f 29 3b 0a 7d 0a  .return(bio);.}.
0f00: 0a 73 74 61 74 69 63 20 69 6e 74 20 42 69 6f 57  .static int BioW
0f10: 72 69 74 65 28 42 49 4f 20 2a 62 69 6f 2c 20 63  rite(BIO *bio, c
0f20: 6f 6e 73 74 20 63 68 61 72 20 2a 62 75 66 2c 20  onst char *buf, 
0f30: 69 6e 74 20 62 75 66 4c 65 6e 29 20 7b 0a 09 54  int bufLen) {..T
0f40: 63 6c 5f 43 68 61 6e 6e 65 6c 20 63 68 61 6e 3b  cl_Channel chan;
0f50: 0a 09 69 6e 74 20 72 65 74 3b 0a 09 69 6e 74 20  ..int ret;..int 
0f60: 74 63 6c 45 6f 66 43 68 61 6e 2c 20 74 63 6c 45  tclEofChan, tclE
0f70: 72 72 6e 6f 3b 0a 0a 09 63 68 61 6e 20 3d 20 54  rrno;...chan = T
0f80: 6c 73 5f 47 65 74 50 61 72 65 6e 74 28 28 53 74  ls_GetParent((St
0f90: 61 74 65 20 2a 29 20 42 49 4f 5f 67 65 74 5f 64  ate *) BIO_get_d
0fa0: 61 74 61 28 62 69 6f 29 2c 20 30 29 3b 0a 0a 09  ata(bio), 0);...
0fb0: 64 70 72 69 6e 74 66 28 22 5b 63 68 61 6e 3d 25  dprintf("[chan=%
0fc0: 70 5d 20 42 69 6f 57 72 69 74 65 28 25 70 2c 20  p] BioWrite(%p, 
0fd0: 3c 62 75 66 3e 2c 20 25 64 29 22 2c 20 28 76 6f  <buf>, %d)", (vo
0fe0: 69 64 20 2a 29 63 68 61 6e 2c 20 28 76 6f 69 64  id *)chan, (void
0ff0: 20 2a 29 20 62 69 6f 2c 20 62 75 66 4c 65 6e 29   *) bio, bufLen)
1000: 3b 0a 0a 09 72 65 74 20 3d 20 54 63 6c 5f 57 72  ;...ret = Tcl_Wr
1010: 69 74 65 52 61 77 28 63 68 61 6e 2c 20 62 75 66  iteRaw(chan, buf
1020: 2c 20 62 75 66 4c 65 6e 29 3b 0a 0a 09 74 63 6c  , bufLen);...tcl
1030: 45 6f 66 43 68 61 6e 20 3d 20 54 63 6c 5f 45 6f  EofChan = Tcl_Eo
1040: 66 28 63 68 61 6e 29 3b 0a 09 74 63 6c 45 72 72  f(chan);..tclErr
1050: 6e 6f 20 3d 20 54 63 6c 5f 47 65 74 45 72 72 6e  no = Tcl_GetErrn
1060: 6f 28 29 3b 0a 0a 09 64 70 72 69 6e 74 66 28 22  o();...dprintf("
1070: 5b 63 68 61 6e 3d 25 70 5d 20 42 69 6f 57 72 69  [chan=%p] BioWri
1080: 74 65 28 25 64 29 20 2d 3e 20 25 64 20 5b 74 63  te(%d) -> %d [tc
1090: 6c 45 6f 66 3d 25 64 3b 20 74 63 6c 45 72 72 6e  lEof=%d; tclErrn
10a0: 6f 3d 25 64 5d 22 2c 20 28 76 6f 69 64 20 2a 29  o=%d]", (void *)
10b0: 20 63 68 61 6e 2c 20 62 75 66 4c 65 6e 2c 20 72   chan, bufLen, r
10c0: 65 74 2c 20 74 63 6c 45 6f 66 43 68 61 6e 2c 20  et, tclEofChan, 
10d0: 54 63 6c 5f 47 65 74 45 72 72 6e 6f 28 29 29 3b  Tcl_GetErrno());
10e0: 0a 0a 09 42 49 4f 5f 63 6c 65 61 72 5f 66 6c 61  ...BIO_clear_fla
10f0: 67 73 28 62 69 6f 2c 20 42 49 4f 5f 46 4c 41 47  gs(bio, BIO_FLAG
1100: 53 5f 57 52 49 54 45 20 7c 20 42 49 4f 5f 46 4c  S_WRITE | BIO_FL
1110: 41 47 53 5f 53 48 4f 55 4c 44 5f 52 45 54 52 59  AGS_SHOULD_RETRY
1120: 29 3b 0a 0a 09 69 66 20 28 74 63 6c 45 6f 66 43  );...if (tclEofC
1130: 68 61 6e 20 26 26 20 72 65 74 20 3c 3d 20 30 29  han && ret <= 0)
1140: 20 7b 0a 09 09 64 70 72 69 6e 74 66 28 22 47 6f   {...dprintf("Go
1150: 74 20 45 4f 46 20 77 68 69 6c 65 20 72 65 61 64  t EOF while read
1160: 69 6e 67 2c 20 72 65 74 75 72 6e 69 6e 67 20 61  ing, returning a
1170: 20 43 6f 6e 6e 65 63 74 69 6f 6e 20 52 65 73 65   Connection Rese
1180: 74 20 65 72 72 6f 72 20 77 68 69 63 68 20 6d 61  t error which ma
1190: 70 73 20 74 6f 20 53 6f 66 74 20 45 4f 46 22 29  ps to Soft EOF")
11a0: 3b 0a 09 09 54 63 6c 5f 53 65 74 45 72 72 6e 6f  ;...Tcl_SetErrno
11b0: 28 45 43 4f 4e 4e 52 45 53 45 54 29 3b 0a 09 09  (ECONNRESET);...
11c0: 72 65 74 20 3d 20 30 3b 0a 09 7d 20 65 6c 73 65  ret = 0;..} else
11d0: 20 69 66 20 28 72 65 74 20 3d 3d 20 30 29 20 7b   if (ret == 0) {
11e0: 0a 09 09 64 70 72 69 6e 74 66 28 22 47 6f 74 20  ...dprintf("Got 
11f0: 30 20 66 72 6f 6d 20 54 63 6c 5f 57 72 69 74 65  0 from Tcl_Write
1200: 52 61 77 2c 20 61 6e 64 20 45 4f 46 20 69 73 20  Raw, and EOF is 
1210: 6e 6f 74 20 73 65 74 3b 20 72 65 74 20 3d 20 30  not set; ret = 0
1220: 22 29 3b 0a 09 09 64 70 72 69 6e 74 66 28 22 53  ");...dprintf("S
1230: 65 74 74 69 6e 67 20 72 65 74 72 79 20 72 65 61  etting retry rea
1240: 64 20 66 6c 61 67 22 29 3b 0a 09 09 42 49 4f 5f  d flag");...BIO_
1250: 73 65 74 5f 72 65 74 72 79 5f 72 65 61 64 28 62  set_retry_read(b
1260: 69 6f 29 3b 0a 09 7d 20 65 6c 73 65 20 69 66 20  io);..} else if 
1270: 28 72 65 74 20 3c 20 30 29 20 7b 0a 09 09 64 70  (ret < 0) {...dp
1280: 72 69 6e 74 66 28 22 57 65 20 67 6f 74 20 73 6f  rintf("We got so
1290: 6d 65 20 6b 69 6e 64 20 6f 66 20 49 2f 4f 20 65  me kind of I/O e
12a0: 72 72 6f 72 22 29 3b 0a 0a 09 09 69 66 20 28 74  rror");....if (t
12b0: 63 6c 45 72 72 6e 6f 20 3d 3d 20 45 41 47 41 49  clErrno == EAGAI
12c0: 4e 29 20 7b 0a 09 09 09 64 70 72 69 6e 74 66 28  N) {....dprintf(
12d0: 22 49 74 27 73 20 45 41 47 41 49 4e 22 29 3b 0a  "It's EAGAIN");.
12e0: 09 09 7d 20 65 6c 73 65 20 7b 0a 09 09 09 64 70  ..} else {....dp
12f0: 72 69 6e 74 66 28 22 49 74 27 73 20 61 6e 20 75  rintf("It's an u
1300: 6e 65 70 78 65 63 74 65 64 20 65 72 72 6f 72 3a  nepxected error:
1310: 20 25 73 2f 25 69 22 2c 20 54 63 6c 5f 45 72 72   %s/%i", Tcl_Err
1320: 6e 6f 4d 73 67 28 74 63 6c 45 72 72 6e 6f 29 2c  noMsg(tclErrno),
1330: 20 74 63 6c 45 72 72 6e 6f 29 3b 0a 09 09 7d 0a   tclErrno);...}.
1340: 09 7d 20 65 6c 73 65 20 7b 0a 09 09 64 70 72 69  .} else {...dpri
1350: 6e 74 66 28 22 53 75 63 63 65 73 73 66 75 6c 6c  ntf("Successfull
1360: 79 20 77 72 6f 74 65 20 73 6f 6d 65 20 64 61 74  y wrote some dat
1370: 61 22 29 3b 0a 09 7d 0a 0a 09 69 66 20 28 72 65  a");..}...if (re
1380: 74 20 21 3d 20 2d 31 20 7c 7c 20 28 72 65 74 20  t != -1 || (ret 
1390: 3d 3d 20 2d 31 20 26 26 20 74 63 6c 45 72 72 6e  == -1 && tclErrn
13a0: 6f 20 3d 3d 20 45 41 47 41 49 4e 29 29 20 7b 0a  o == EAGAIN)) {.
13b0: 09 09 69 66 20 28 42 49 4f 5f 73 68 6f 75 6c 64  ..if (BIO_should
13c0: 5f 72 65 61 64 28 62 69 6f 29 29 20 7b 0a 09 09  _read(bio)) {...
13d0: 09 64 70 72 69 6e 74 66 28 22 53 65 74 74 69 6e  .dprintf("Settin
13e0: 67 20 73 68 6f 75 6c 64 20 72 65 74 72 79 20 72  g should retry r
13f0: 65 61 64 20 66 6c 61 67 22 29 3b 0a 0a 09 09 09  ead flag");.....
1400: 42 49 4f 5f 73 65 74 5f 72 65 74 72 79 5f 72 65  BIO_set_retry_re
1410: 61 64 28 62 69 6f 29 3b 0a 09 09 7d 0a 09 7d 0a  ad(bio);...}..}.
1420: 0a 09 72 65 74 75 72 6e 28 72 65 74 29 3b 0a 7d  ..return(ret);.}
1430: 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 42 69 6f  ..static int Bio
1440: 52 65 61 64 28 42 49 4f 20 2a 62 69 6f 2c 20 63  Read(BIO *bio, c
1450: 68 61 72 20 2a 62 75 66 2c 20 69 6e 74 20 62 75  har *buf, int bu
1460: 66 4c 65 6e 29 20 7b 0a 09 54 63 6c 5f 43 68 61  fLen) {..Tcl_Cha
1470: 6e 6e 65 6c 20 63 68 61 6e 3b 0a 09 69 6e 74 20  nnel chan;..int 
1480: 72 65 74 20 3d 20 30 3b 0a 09 69 6e 74 20 74 63  ret = 0;..int tc
1490: 6c 45 6f 66 43 68 61 6e 2c 20 74 63 6c 45 72 72  lEofChan, tclErr
14a0: 6e 6f 3b 0a 0a 09 63 68 61 6e 20 3d 20 54 6c 73  no;...chan = Tls
14b0: 5f 47 65 74 50 61 72 65 6e 74 28 28 53 74 61 74  _GetParent((Stat
14c0: 65 20 2a 29 20 42 49 4f 5f 67 65 74 5f 64 61 74  e *) BIO_get_dat
14d0: 61 28 62 69 6f 29 2c 20 30 29 3b 0a 0a 09 64 70  a(bio), 0);...dp
14e0: 72 69 6e 74 66 28 22 5b 63 68 61 6e 3d 25 70 5d  rintf("[chan=%p]
14f0: 20 42 69 6f 52 65 61 64 28 25 70 2c 20 3c 62 75   BioRead(%p, <bu
1500: 66 3e 2c 20 25 64 29 22 2c 20 28 76 6f 69 64 20  f>, %d)", (void 
1510: 2a 29 20 63 68 61 6e 2c 20 28 76 6f 69 64 20 2a  *) chan, (void *
1520: 29 20 62 69 6f 2c 20 62 75 66 4c 65 6e 29 3b 0a  ) bio, bufLen);.
1530: 0a 09 69 66 20 28 62 75 66 20 3d 3d 20 4e 55 4c  ..if (buf == NUL
1540: 4c 29 20 7b 0a 09 09 72 65 74 75 72 6e 20 30 3b  L) {...return 0;
1550: 0a 09 7d 0a 0a 09 72 65 74 20 3d 20 54 63 6c 5f  ..}...ret = Tcl_
1560: 52 65 61 64 52 61 77 28 63 68 61 6e 2c 20 62 75  ReadRaw(chan, bu
1570: 66 2c 20 62 75 66 4c 65 6e 29 3b 0a 0a 09 74 63  f, bufLen);...tc
1580: 6c 45 6f 66 43 68 61 6e 20 3d 20 54 63 6c 5f 45  lEofChan = Tcl_E
1590: 6f 66 28 63 68 61 6e 29 3b 0a 09 74 63 6c 45 72  of(chan);..tclEr
15a0: 72 6e 6f 20 3d 20 54 63 6c 5f 47 65 74 45 72 72  rno = Tcl_GetErr
15b0: 6e 6f 28 29 3b 0a 0a 09 64 70 72 69 6e 74 66 28  no();...dprintf(
15c0: 22 5b 63 68 61 6e 3d 25 70 5d 20 42 69 6f 52 65  "[chan=%p] BioRe
15d0: 61 64 28 25 64 29 20 2d 3e 20 25 64 20 5b 74 63  ad(%d) -> %d [tc
15e0: 6c 45 6f 66 3d 25 64 3b 20 74 63 6c 45 72 72 6e  lEof=%d; tclErrn
15f0: 6f 3d 25 64 5d 22 2c 20 28 76 6f 69 64 20 2a 29  o=%d]", (void *)
1600: 20 63 68 61 6e 2c 20 62 75 66 4c 65 6e 2c 20 72   chan, bufLen, r
1610: 65 74 2c 20 74 63 6c 45 6f 66 43 68 61 6e 2c 20  et, tclEofChan, 
1620: 74 63 6c 45 72 72 6e 6f 29 3b 0a 0a 09 42 49 4f  tclErrno);...BIO
1630: 5f 63 6c 65 61 72 5f 66 6c 61 67 73 28 62 69 6f  _clear_flags(bio
1640: 2c 20 42 49 4f 5f 46 4c 41 47 53 5f 52 45 41 44  , BIO_FLAGS_READ
1650: 20 7c 20 42 49 4f 5f 46 4c 41 47 53 5f 53 48 4f   | BIO_FLAGS_SHO
1660: 55 4c 44 5f 52 45 54 52 59 29 3b 0a 0a 09 69 66  ULD_RETRY);...if
1670: 20 28 74 63 6c 45 6f 66 43 68 61 6e 20 26 26 20   (tclEofChan && 
1680: 72 65 74 20 3c 3d 20 30 29 20 7b 0a 09 09 64 70  ret <= 0) {...dp
1690: 72 69 6e 74 66 28 22 47 6f 74 20 45 4f 46 20 77  rintf("Got EOF w
16a0: 68 69 6c 65 20 72 65 61 64 69 6e 67 2c 20 72 65  hile reading, re
16b0: 74 75 72 6e 69 6e 67 20 61 20 43 6f 6e 6e 65 63  turning a Connec
16c0: 74 69 6f 6e 20 52 65 73 65 74 20 65 72 72 6f 72  tion Reset error
16d0: 20 77 68 69 63 68 20 6d 61 70 73 20 74 6f 20 53   which maps to S
16e0: 6f 66 74 20 45 4f 46 22 29 3b 0a 09 09 54 63 6c  oft EOF");...Tcl
16f0: 5f 53 65 74 45 72 72 6e 6f 28 45 43 4f 4e 4e 52  _SetErrno(ECONNR
1700: 45 53 45 54 29 3b 0a 09 09 72 65 74 20 3d 20 30  ESET);...ret = 0
1710: 3b 0a 09 7d 20 65 6c 73 65 20 69 66 20 28 72 65  ;..} else if (re
1720: 74 20 3d 3d 20 30 29 20 7b 0a 09 09 64 70 72 69  t == 0) {...dpri
1730: 6e 74 66 28 22 47 6f 74 20 30 20 66 72 6f 6d 20  ntf("Got 0 from 
1740: 54 63 6c 5f 52 65 61 64 20 6f 72 20 54 63 6c 5f  Tcl_Read or Tcl_
1750: 52 65 61 64 52 61 77 2c 20 61 6e 64 20 45 4f 46  ReadRaw, and EOF
1760: 20 69 73 20 6e 6f 74 20 73 65 74 3b 20 72 65 74   is not set; ret
1770: 20 3d 20 30 22 29 3b 0a 09 09 64 70 72 69 6e 74   = 0");...dprint
1780: 66 28 22 53 65 74 74 69 6e 67 20 72 65 74 72 79  f("Setting retry
1790: 20 72 65 61 64 20 66 6c 61 67 22 29 3b 0a 09 09   read flag");...
17a0: 42 49 4f 5f 73 65 74 5f 72 65 74 72 79 5f 72 65  BIO_set_retry_re
17b0: 61 64 28 62 69 6f 29 3b 0a 09 7d 20 65 6c 73 65  ad(bio);..} else
17c0: 20 69 66 20 28 72 65 74 20 3c 20 30 29 20 7b 0a   if (ret < 0) {.
17d0: 09 09 64 70 72 69 6e 74 66 28 22 57 65 20 67 6f  ..dprintf("We go
17e0: 74 20 73 6f 6d 65 20 6b 69 6e 64 20 6f 66 20 49  t some kind of I
17f0: 2f 4f 20 65 72 72 6f 72 22 29 3b 0a 0a 09 09 69  /O error");....i
1800: 66 20 28 74 63 6c 45 72 72 6e 6f 20 3d 3d 20 45  f (tclErrno == E
1810: 41 47 41 49 4e 29 20 7b 0a 09 09 09 64 70 72 69  AGAIN) {....dpri
1820: 6e 74 66 28 22 49 74 27 73 20 45 41 47 41 49 4e  ntf("It's EAGAIN
1830: 22 29 3b 0a 09 09 7d 20 65 6c 73 65 20 7b 0a 09  ");...} else {..
1840: 09 09 64 70 72 69 6e 74 66 28 22 49 74 27 73 20  ..dprintf("It's 
1850: 61 6e 20 75 6e 65 70 78 65 63 74 65 64 20 65 72  an unepxected er
1860: 72 6f 72 3a 20 25 73 2f 25 69 22 2c 20 54 63 6c  ror: %s/%i", Tcl
1870: 5f 45 72 72 6e 6f 4d 73 67 28 74 63 6c 45 72 72  _ErrnoMsg(tclErr
1880: 6e 6f 29 2c 20 74 63 6c 45 72 72 6e 6f 29 3b 0a  no), tclErrno);.
1890: 09 09 7d 0a 09 7d 20 65 6c 73 65 20 7b 0a 09 09  ..}..} else {...
18a0: 64 70 72 69 6e 74 66 28 22 53 75 63 63 65 73 73  dprintf("Success
18b0: 66 75 6c 6c 79 20 72 65 61 64 20 73 6f 6d 65 20  fully read some 
18c0: 64 61 74 61 22 29 3b 0a 09 7d 0a 0a 09 69 66 20  data");..}...if 
18d0: 28 72 65 74 20 21 3d 20 2d 31 20 7c 7c 20 28 72  (ret != -1 || (r
18e0: 65 74 20 3d 3d 20 2d 31 20 26 26 20 74 63 6c 45  et == -1 && tclE
18f0: 72 72 6e 6f 20 3d 3d 20 45 41 47 41 49 4e 29 29  rrno == EAGAIN))
1900: 20 7b 0a 09 09 69 66 20 28 42 49 4f 5f 73 68 6f   {...if (BIO_sho
1910: 75 6c 64 5f 77 72 69 74 65 28 62 69 6f 29 29 20  uld_write(bio)) 
1920: 7b 0a 09 09 09 64 70 72 69 6e 74 66 28 22 53 65  {....dprintf("Se
1930: 74 74 69 6e 67 20 73 68 6f 75 6c 64 20 72 65 74  tting should ret
1940: 72 79 20 77 72 69 74 65 20 66 6c 61 67 22 29 3b  ry write flag");
1950: 0a 0a 09 09 09 42 49 4f 5f 73 65 74 5f 72 65 74  .....BIO_set_ret
1960: 72 79 5f 77 72 69 74 65 28 62 69 6f 29 3b 0a 09  ry_write(bio);..
1970: 09 7d 0a 09 7d 0a 0a 09 64 70 72 69 6e 74 66 28  .}..}...dprintf(
1980: 22 42 69 6f 52 65 61 64 28 25 70 2c 20 3c 62 75  "BioRead(%p, <bu
1990: 66 3e 2c 20 25 64 29 20 5b 25 70 5d 20 72 65 74  f>, %d) [%p] ret
19a0: 75 72 6e 69 6e 67 20 25 69 22 2c 20 28 76 6f 69  urning %i", (voi
19b0: 64 20 2a 29 20 62 69 6f 2c 20 62 75 66 4c 65 6e  d *) bio, bufLen
19c0: 2c 20 28 76 6f 69 64 20 2a 29 20 63 68 61 6e 2c  , (void *) chan,
19d0: 20 72 65 74 29 3b 0a 0a 09 72 65 74 75 72 6e 28   ret);...return(
19e0: 72 65 74 29 3b 0a 7d 0a 0a 73 74 61 74 69 63 20  ret);.}..static 
19f0: 69 6e 74 20 42 69 6f 50 75 74 73 28 42 49 4f 20  int BioPuts(BIO 
1a00: 2a 62 69 6f 2c 20 63 6f 6e 73 74 20 63 68 61 72  *bio, const char
1a10: 20 2a 73 74 72 29 20 7b 0a 09 64 70 72 69 6e 74   *str) {..dprint
1a20: 66 28 22 42 69 6f 50 75 74 73 28 25 70 2c 20 3c  f("BioPuts(%p, <
1a30: 73 74 72 69 6e 67 3a 25 70 3e 29 20 63 61 6c 6c  string:%p>) call
1a40: 65 64 22 2c 20 62 69 6f 2c 20 73 74 72 29 3b 0a  ed", bio, str);.
1a50: 0a 09 72 65 74 75 72 6e 20 42 69 6f 57 72 69 74  ..return BioWrit
1a60: 65 28 62 69 6f 2c 20 73 74 72 2c 20 28 69 6e 74  e(bio, str, (int
1a70: 29 20 73 74 72 6c 65 6e 28 73 74 72 29 29 3b 0a  ) strlen(str));.
1a80: 7d 0a 0a 73 74 61 74 69 63 20 6c 6f 6e 67 20 42  }..static long B
1a90: 69 6f 43 74 72 6c 28 42 49 4f 20 2a 62 69 6f 2c  ioCtrl(BIO *bio,
1aa0: 20 69 6e 74 20 63 6d 64 2c 20 6c 6f 6e 67 20 6e   int cmd, long n
1ab0: 75 6d 2c 20 76 6f 69 64 20 2a 70 74 72 29 20 7b  um, void *ptr) {
1ac0: 0a 09 54 63 6c 5f 43 68 61 6e 6e 65 6c 20 63 68  ..Tcl_Channel ch
1ad0: 61 6e 3b 0a 09 6c 6f 6e 67 20 72 65 74 20 3d 20  an;..long ret = 
1ae0: 31 3b 0a 0a 09 63 68 61 6e 20 3d 20 54 6c 73 5f  1;...chan = Tls_
1af0: 47 65 74 50 61 72 65 6e 74 28 28 53 74 61 74 65  GetParent((State
1b00: 20 2a 29 20 42 49 4f 5f 67 65 74 5f 64 61 74 61   *) BIO_get_data
1b10: 28 62 69 6f 29 2c 20 30 29 3b 0a 0a 09 64 70 72  (bio), 0);...dpr
1b20: 69 6e 74 66 28 22 42 69 6f 43 74 72 6c 28 25 70  intf("BioCtrl(%p
1b30: 2c 20 30 78 25 78 2c 20 30 78 25 78 2c 20 25 70  , 0x%x, 0x%x, %p
1b40: 29 22 2c 20 28 76 6f 69 64 20 2a 29 20 62 69 6f  )", (void *) bio
1b50: 2c 20 28 75 6e 73 69 67 6e 65 64 20 69 6e 74 29  , (unsigned int)
1b60: 20 63 6d 64 2c 20 28 75 6e 73 69 67 6e 65 64 20   cmd, (unsigned 
1b70: 69 6e 74 29 20 6e 75 6d 2c 20 28 76 6f 69 64 20  int) num, (void 
1b80: 2a 29 20 70 74 72 29 3b 0a 0a 09 73 77 69 74 63  *) ptr);...switc
1b90: 68 20 28 63 6d 64 29 20 7b 0a 09 09 63 61 73 65  h (cmd) {...case
1ba0: 20 42 49 4f 5f 43 54 52 4c 5f 52 45 53 45 54 3a   BIO_CTRL_RESET:
1bb0: 0a 09 09 09 64 70 72 69 6e 74 66 28 22 47 6f 74  ....dprintf("Got
1bc0: 20 42 49 4f 5f 43 54 52 4c 5f 52 45 53 45 54 22   BIO_CTRL_RESET"
1bd0: 29 3b 0a 09 09 09 6e 75 6d 20 3d 20 30 3b 0a 09  );....num = 0;..
1be0: 09 63 61 73 65 20 42 49 4f 5f 43 5f 46 49 4c 45  .case BIO_C_FILE
1bf0: 5f 53 45 45 4b 3a 0a 09 09 09 64 70 72 69 6e 74  _SEEK:....dprint
1c00: 66 28 22 47 6f 74 20 42 49 4f 5f 43 5f 46 49 4c  f("Got BIO_C_FIL
1c10: 45 5f 53 45 45 4b 22 29 3b 0a 09 09 63 61 73 65  E_SEEK");...case
1c20: 20 42 49 4f 5f 43 5f 46 49 4c 45 5f 54 45 4c 4c   BIO_C_FILE_TELL
1c30: 3a 0a 09 09 09 64 70 72 69 6e 74 66 28 22 47 6f  :....dprintf("Go
1c40: 74 20 42 49 4f 5f 43 5f 46 49 4c 45 5f 54 45 4c  t BIO_C_FILE_TEL
1c50: 4c 22 29 3b 0a 09 09 09 72 65 74 20 3d 20 30 3b  L");....ret = 0;
1c60: 0a 09 09 09 62 72 65 61 6b 3b 0a 09 09 63 61 73  ....break;...cas
1c70: 65 20 42 49 4f 5f 43 54 52 4c 5f 49 4e 46 4f 3a  e BIO_CTRL_INFO:
1c80: 0a 09 09 09 64 70 72 69 6e 74 66 28 22 47 6f 74  ....dprintf("Got
1c90: 20 42 49 4f 5f 43 54 52 4c 5f 49 4e 46 4f 22 29   BIO_CTRL_INFO")
1ca0: 3b 0a 09 09 09 72 65 74 20 3d 20 31 3b 0a 09 09  ;....ret = 1;...
1cb0: 09 62 72 65 61 6b 3b 0a 09 09 63 61 73 65 20 42  .break;...case B
1cc0: 49 4f 5f 43 5f 53 45 54 5f 46 44 3a 0a 09 09 09  IO_C_SET_FD:....
1cd0: 64 70 72 69 6e 74 66 28 22 55 6e 73 75 70 70 6f  dprintf("Unsuppo
1ce0: 72 74 65 64 20 63 61 6c 6c 3a 20 42 49 4f 5f 43  rted call: BIO_C
1cf0: 5f 53 45 54 5f 46 44 22 29 3b 0a 09 09 09 72 65  _SET_FD");....re
1d00: 74 20 3d 20 2d 31 3b 0a 09 09 09 62 72 65 61 6b  t = -1;....break
1d10: 3b 0a 09 09 63 61 73 65 20 42 49 4f 5f 43 5f 47  ;...case BIO_C_G
1d20: 45 54 5f 46 44 3a 0a 09 09 09 64 70 72 69 6e 74  ET_FD:....dprint
1d30: 66 28 22 55 6e 73 75 70 70 6f 72 74 65 64 20 63  f("Unsupported c
1d40: 61 6c 6c 3a 20 42 49 4f 5f 43 5f 47 45 54 5f 46  all: BIO_C_GET_F
1d50: 44 22 29 3b 0a 09 09 09 72 65 74 20 3d 20 2d 31  D");....ret = -1
1d60: 3b 0a 09 09 09 62 72 65 61 6b 3b 0a 09 09 63 61  ;....break;...ca
1d70: 73 65 20 42 49 4f 5f 43 54 52 4c 5f 47 45 54 5f  se BIO_CTRL_GET_
1d80: 43 4c 4f 53 45 3a 0a 09 09 09 64 70 72 69 6e 74  CLOSE:....dprint
1d90: 66 28 22 47 6f 74 20 42 49 4f 5f 43 54 52 4c 5f  f("Got BIO_CTRL_
1da0: 43 4c 4f 53 45 22 29 3b 0a 09 09 09 72 65 74 20  CLOSE");....ret 
1db0: 3d 20 42 49 4f 5f 67 65 74 5f 73 68 75 74 64 6f  = BIO_get_shutdo
1dc0: 77 6e 28 62 69 6f 29 3b 0a 09 09 09 62 72 65 61  wn(bio);....brea
1dd0: 6b 3b 0a 09 09 63 61 73 65 20 42 49 4f 5f 43 54  k;...case BIO_CT
1de0: 52 4c 5f 53 45 54 5f 43 4c 4f 53 45 3a 0a 09 09  RL_SET_CLOSE:...
1df0: 09 64 70 72 69 6e 74 66 28 22 47 6f 74 20 42 49  .dprintf("Got BI
1e00: 4f 5f 53 45 54 5f 43 4c 4f 53 45 22 29 3b 0a 09  O_SET_CLOSE");..
1e10: 09 09 42 49 4f 5f 73 65 74 5f 73 68 75 74 64 6f  ..BIO_set_shutdo
1e20: 77 6e 28 62 69 6f 2c 20 6e 75 6d 29 3b 0a 09 09  wn(bio, num);...
1e30: 09 62 72 65 61 6b 3b 0a 09 09 63 61 73 65 20 42  .break;...case B
1e40: 49 4f 5f 43 54 52 4c 5f 45 4f 46 3a 0a 09 09 09  IO_CTRL_EOF:....
1e50: 64 70 72 69 6e 74 66 28 22 47 6f 74 20 42 49 4f  dprintf("Got BIO
1e60: 5f 43 54 52 4c 5f 45 4f 46 22 29 3b 0a 09 09 09  _CTRL_EOF");....
1e70: 72 65 74 20 3d 20 54 63 6c 5f 45 6f 66 28 63 68  ret = Tcl_Eof(ch
1e80: 61 6e 29 3b 0a 09 09 09 62 72 65 61 6b 3b 0a 09  an);....break;..
1e90: 09 63 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f 50  .case BIO_CTRL_P
1ea0: 45 4e 44 49 4e 47 3a 0a 09 09 09 64 70 72 69 6e  ENDING:....dprin
1eb0: 74 66 28 22 47 6f 74 20 42 49 4f 5f 43 54 52 4c  tf("Got BIO_CTRL
1ec0: 5f 50 45 4e 44 49 4e 47 22 29 3b 0a 09 09 09 72  _PENDING");....r
1ed0: 65 74 20 3d 20 28 28 63 68 61 6e 29 20 3f 20 54  et = ((chan) ? T
1ee0: 63 6c 5f 49 6e 70 75 74 42 75 66 66 65 72 65 64  cl_InputBuffered
1ef0: 28 63 68 61 6e 29 20 3a 20 30 29 3b 0a 09 09 09  (chan) : 0);....
1f00: 64 70 72 69 6e 74 66 28 22 42 49 4f 5f 43 54 52  dprintf("BIO_CTR
1f10: 4c 5f 50 45 4e 44 49 4e 47 28 25 64 29 22 2c 20  L_PENDING(%d)", 
1f20: 28 69 6e 74 29 20 72 65 74 29 3b 0a 09 09 09 62  (int) ret);....b
1f30: 72 65 61 6b 3b 0a 09 09 63 61 73 65 20 42 49 4f  reak;...case BIO
1f40: 5f 43 54 52 4c 5f 57 50 45 4e 44 49 4e 47 3a 0a  _CTRL_WPENDING:.
1f50: 09 09 09 64 70 72 69 6e 74 66 28 22 47 6f 74 20  ...dprintf("Got 
1f60: 42 49 4f 5f 43 54 52 4c 5f 57 50 45 4e 44 49 4e  BIO_CTRL_WPENDIN
1f70: 47 22 29 3b 0a 09 09 09 72 65 74 20 3d 20 30 3b  G");....ret = 0;
1f80: 0a 09 09 09 62 72 65 61 6b 3b 0a 09 09 63 61 73  ....break;...cas
1f90: 65 20 42 49 4f 5f 43 54 52 4c 5f 44 55 50 3a 0a  e BIO_CTRL_DUP:.
1fa0: 09 09 09 64 70 72 69 6e 74 66 28 22 47 6f 74 20  ...dprintf("Got 
1fb0: 42 49 4f 5f 43 54 52 4c 5f 44 55 50 22 29 3b 0a  BIO_CTRL_DUP");.
1fc0: 09 09 09 62 72 65 61 6b 3b 0a 09 09 63 61 73 65  ...break;...case
1fd0: 20 42 49 4f 5f 43 54 52 4c 5f 46 4c 55 53 48 3a   BIO_CTRL_FLUSH:
1fe0: 0a 09 09 09 64 70 72 69 6e 74 66 28 22 47 6f 74  ....dprintf("Got
1ff0: 20 42 49 4f 5f 43 54 52 4c 5f 46 4c 55 53 48 22   BIO_CTRL_FLUSH"
2000: 29 3b 0a 09 09 09 72 65 74 20 3d 20 28 28 54 63  );....ret = ((Tc
2010: 6c 5f 57 72 69 74 65 52 61 77 28 63 68 61 6e 2c  l_WriteRaw(chan,
2020: 20 22 22 2c 20 30 29 20 3e 3d 20 30 29 20 3f 20   "", 0) >= 0) ? 
2030: 31 20 3a 20 2d 31 29 3b 0a 09 09 09 64 70 72 69  1 : -1);....dpri
2040: 6e 74 66 28 22 42 49 4f 5f 43 54 52 4c 5f 46 4c  ntf("BIO_CTRL_FL
2050: 55 53 48 20 72 65 74 75 72 6e 69 6e 67 20 76 61  USH returning va
2060: 6c 75 65 20 25 6c 69 22 2c 20 72 65 74 29 3b 0a  lue %li", ret);.
2070: 09 09 09 62 72 65 61 6b 3b 0a 09 09 64 65 66 61  ...break;...defa
2080: 75 6c 74 3a 0a 09 09 09 64 70 72 69 6e 74 66 28  ult:....dprintf(
2090: 22 47 6f 74 20 75 6e 6b 6e 6f 77 6e 20 63 6f 6e  "Got unknown con
20a0: 74 72 6f 6c 20 63 6f 6d 6d 61 6e 64 20 28 25 69  trol command (%i
20b0: 29 22 2c 20 63 6d 64 29 3b 0a 09 09 09 72 65 74  )", cmd);....ret
20c0: 20 3d 20 2d 32 3b 0a 09 09 09 62 72 65 61 6b 3b   = -2;....break;
20d0: 0a 09 7d 0a 0a 09 72 65 74 75 72 6e 28 72 65 74  ..}...return(ret
20e0: 29 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74  );.}..static int
20f0: 20 42 69 6f 4e 65 77 28 42 49 4f 20 2a 62 69 6f   BioNew(BIO *bio
2100: 29 20 7b 0a 09 64 70 72 69 6e 74 66 28 22 42 69  ) {..dprintf("Bi
2110: 6f 4e 65 77 28 25 70 29 20 63 61 6c 6c 65 64 22  oNew(%p) called"
2120: 2c 20 62 69 6f 29 3b 0a 0a 09 42 49 4f 5f 73 65  , bio);...BIO_se
2130: 74 5f 69 6e 69 74 28 62 69 6f 2c 20 30 29 3b 0a  t_init(bio, 0);.
2140: 09 42 49 4f 5f 73 65 74 5f 64 61 74 61 28 62 69  .BIO_set_data(bi
2150: 6f 2c 20 4e 55 4c 4c 29 3b 0a 09 42 49 4f 5f 63  o, NULL);..BIO_c
2160: 6c 65 61 72 5f 66 6c 61 67 73 28 62 69 6f 2c 20  lear_flags(bio, 
2170: 2d 31 29 3b 0a 0a 09 72 65 74 75 72 6e 28 31 29  -1);...return(1)
2180: 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 20  ;.}..static int 
2190: 42 69 6f 46 72 65 65 28 42 49 4f 20 2a 62 69 6f  BioFree(BIO *bio
21a0: 29 20 7b 0a 09 69 66 20 28 62 69 6f 20 3d 3d 20  ) {..if (bio == 
21b0: 4e 55 4c 4c 29 20 7b 0a 09 09 72 65 74 75 72 6e  NULL) {...return
21c0: 28 30 29 3b 0a 09 7d 0a 0a 09 64 70 72 69 6e 74  (0);..}...dprint
21d0: 66 28 22 42 69 6f 46 72 65 65 28 25 70 29 20 63  f("BioFree(%p) c
21e0: 61 6c 6c 65 64 22 2c 20 62 69 6f 29 3b 0a 0a 09  alled", bio);...
21f0: 69 66 20 28 42 49 4f 5f 67 65 74 5f 73 68 75 74  if (BIO_get_shut
2200: 64 6f 77 6e 28 62 69 6f 29 29 20 7b 0a 09 09 69  down(bio)) {...i
2210: 66 20 28 42 49 4f 5f 67 65 74 5f 69 6e 69 74 28  f (BIO_get_init(
2220: 62 69 6f 29 29 20 7b 0a 09 09 09 2f 2a 73 68 75  bio)) {..../*shu
2230: 74 64 6f 77 6e 28 62 69 6f 2d 3e 6e 75 6d 2c 20  tdown(bio->num, 
2240: 32 29 20 2a 2f 0a 09 09 09 2f 2a 63 6c 6f 73 65  2) */..../*close
2250: 73 6f 63 6b 65 74 28 62 69 6f 2d 3e 6e 75 6d 29  socket(bio->num)
2260: 20 2a 2f 0a 09 09 7d 0a 0a 09 09 42 49 4f 5f 73   */...}....BIO_s
2270: 65 74 5f 69 6e 69 74 28 62 69 6f 2c 20 30 29 3b  et_init(bio, 0);
2280: 0a 09 09 42 49 4f 5f 63 6c 65 61 72 5f 66 6c 61  ...BIO_clear_fla
2290: 67 73 28 62 69 6f 2c 20 2d 31 29 3b 0a 09 7d 0a  gs(bio, -1);..}.
22a0: 0a 09 72 65 74 75 72 6e 28 31 29 3b 0a 7d 0a     ..return(1);.}.