Hex Artifact Content

Artifact 13299d5667420537c7ded5ddf080bc68ced9cc91a9458f213136ef2f174ad3f5:


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 4f 70 65 6e 53 53 4c 20 74 6f 20 54  ace OpenSSL to T
0070: 43 4c 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 2f 2a  e "tlsInt.h"../*
0090: 20 43 61 6c 6c 65 64 20 62 79 20 53 53 4c 5f 77   Called by SSL_w
00a0: 72 69 74 65 28 29 20 2a 2f 0a 73 74 61 74 69 63  rite() */.static
00b0: 20 69 6e 74 20 42 69 6f 57 72 69 74 65 28 42 49   int BioWrite(BI
00c0: 4f 20 2a 62 69 6f 2c 20 63 6f 6e 73 74 20 63 68  O *bio, const ch
00d0: 61 72 20 2a 62 75 66 2c 20 69 6e 74 20 62 75 66  ar *buf, int buf
00e0: 4c 65 6e 29 20 7b 0a 20 20 20 20 54 63 6c 5f 43  Len) {.    Tcl_C
00f0: 68 61 6e 6e 65 6c 20 63 68 61 6e 3b 0a 20 20 20  hannel chan;.   
0100: 20 54 63 6c 5f 53 69 7a 65 20 72 65 74 3b 0a 20   Tcl_Size ret;. 
0110: 20 20 20 69 6e 74 20 74 63 6c 45 6f 66 43 68 61     int tclEofCha
0120: 6e 2c 20 74 63 6c 45 72 72 6e 6f 3b 0a 0a 20 20  n, tclErrno;..  
0130: 20 20 63 68 61 6e 20 3d 20 54 6c 73 5f 47 65 74    chan = Tls_Get
0140: 50 61 72 65 6e 74 28 28 53 74 61 74 65 20 2a 29  Parent((State *)
0150: 20 42 49 4f 5f 67 65 74 5f 64 61 74 61 28 62 69   BIO_get_data(bi
0160: 6f 29 2c 20 30 29 3b 0a 0a 20 20 20 20 64 70 72  o), 0);..    dpr
0170: 69 6e 74 66 28 22 5b 63 68 61 6e 3d 25 70 5d 20  intf("[chan=%p] 
0180: 42 69 6f 57 72 69 74 65 28 25 70 2c 20 3c 62 75  BioWrite(%p, <bu
0190: 66 3e 2c 20 25 64 29 22 2c 20 28 76 6f 69 64 20  f>, %d)", (void 
01a0: 2a 29 63 68 61 6e 2c 20 28 76 6f 69 64 20 2a 29  *)chan, (void *)
01b0: 20 62 69 6f 2c 20 62 75 66 4c 65 6e 29 3b 0a 0a   bio, bufLen);..
01c0: 20 20 20 20 72 65 74 20 3d 20 54 63 6c 5f 57 72      ret = Tcl_Wr
01d0: 69 74 65 52 61 77 28 63 68 61 6e 2c 20 62 75 66  iteRaw(chan, buf
01e0: 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 62 75 66  , (Tcl_Size) buf
01f0: 4c 65 6e 29 3b 0a 0a 20 20 20 20 74 63 6c 45 6f  Len);..    tclEo
0200: 66 43 68 61 6e 20 3d 20 54 63 6c 5f 45 6f 66 28  fChan = Tcl_Eof(
0210: 63 68 61 6e 29 3b 0a 20 20 20 20 74 63 6c 45 72  chan);.    tclEr
0220: 72 6e 6f 20 3d 20 54 63 6c 5f 47 65 74 45 72 72  rno = Tcl_GetErr
0230: 6e 6f 28 29 3b 0a 0a 20 20 20 20 64 70 72 69 6e  no();..    dprin
0240: 74 66 28 22 5b 63 68 61 6e 3d 25 70 5d 20 42 69  tf("[chan=%p] Bi
0250: 6f 57 72 69 74 65 28 25 64 29 20 2d 3e 20 25 22  oWrite(%d) -> %"
0260: 20 54 43 4c 5f 53 49 5a 45 5f 4d 4f 44 49 46 49   TCL_SIZE_MODIFI
0270: 45 52 20 22 64 20 5b 74 63 6c 45 6f 66 3d 25 64  ER "d [tclEof=%d
0280: 3b 20 74 63 6c 45 72 72 6e 6f 3d 25 64 5d 22 2c  ; tclErrno=%d]",
0290: 0a 09 28 76 6f 69 64 20 2a 29 20 63 68 61 6e 2c  ..(void *) chan,
02a0: 20 62 75 66 4c 65 6e 2c 20 72 65 74 2c 20 74 63   bufLen, ret, tc
02b0: 6c 45 6f 66 43 68 61 6e 2c 20 74 63 6c 45 72 72  lEofChan, tclErr
02c0: 6e 6f 29 3b 0a 0a 20 20 20 20 42 49 4f 5f 63 6c  no);..    BIO_cl
02d0: 65 61 72 5f 66 6c 61 67 73 28 62 69 6f 2c 20 42  ear_flags(bio, B
02e0: 49 4f 5f 46 4c 41 47 53 5f 57 52 49 54 45 20 7c  IO_FLAGS_WRITE |
02f0: 20 42 49 4f 5f 46 4c 41 47 53 5f 53 48 4f 55 4c   BIO_FLAGS_SHOUL
0300: 44 5f 52 45 54 52 59 29 3b 0a 0a 20 20 20 20 69  D_RETRY);..    i
0310: 66 20 28 74 63 6c 45 6f 66 43 68 61 6e 20 26 26  f (tclEofChan &&
0320: 20 72 65 74 20 3c 3d 20 30 29 20 7b 0a 09 64 70   ret <= 0) {..dp
0330: 72 69 6e 74 66 28 22 47 6f 74 20 45 4f 46 20 77  rintf("Got EOF w
0340: 68 69 6c 65 20 72 65 61 64 69 6e 67 2c 20 72 65  hile reading, re
0350: 74 75 72 6e 69 6e 67 20 61 20 43 6f 6e 6e 65 63  turning a Connec
0360: 74 69 6f 6e 20 52 65 73 65 74 20 65 72 72 6f 72  tion Reset error
0370: 20 77 68 69 63 68 20 6d 61 70 73 20 74 6f 20 53   which maps to S
0380: 6f 66 74 20 45 4f 46 22 29 3b 0a 09 54 63 6c 5f  oft EOF");..Tcl_
0390: 53 65 74 45 72 72 6e 6f 28 45 43 4f 4e 4e 52 45  SetErrno(ECONNRE
03a0: 53 45 54 29 3b 0a 09 72 65 74 20 3d 20 30 3b 0a  SET);..ret = 0;.
03b0: 0a 20 20 20 20 7d 20 65 6c 73 65 20 69 66 20 28  .    } else if (
03c0: 72 65 74 20 3d 3d 20 30 29 20 7b 0a 09 64 70 72  ret == 0) {..dpr
03d0: 69 6e 74 66 28 22 47 6f 74 20 30 20 66 72 6f 6d  intf("Got 0 from
03e0: 20 54 63 6c 5f 57 72 69 74 65 52 61 77 2c 20 61   Tcl_WriteRaw, a
03f0: 6e 64 20 45 4f 46 20 69 73 20 6e 6f 74 20 73 65  nd EOF is not se
0400: 74 3b 20 72 65 74 20 3d 20 30 22 29 3b 0a 09 64  t; ret = 0");..d
0410: 70 72 69 6e 74 66 28 22 53 65 74 74 69 6e 67 20  printf("Setting 
0420: 72 65 74 72 79 20 72 65 61 64 20 66 6c 61 67 22  retry read flag"
0430: 29 3b 0a 09 42 49 4f 5f 73 65 74 5f 72 65 74 72  );..BIO_set_retr
0440: 79 5f 72 65 61 64 28 62 69 6f 29 3b 0a 0a 20 20  y_read(bio);..  
0450: 20 20 7d 20 65 6c 73 65 20 69 66 20 28 72 65 74    } else if (ret
0460: 20 3c 20 30 29 20 7b 0a 09 64 70 72 69 6e 74 66   < 0) {..dprintf
0470: 28 22 57 65 20 67 6f 74 20 73 6f 6d 65 20 6b 69  ("We got some ki
0480: 6e 64 20 6f 66 20 49 2f 4f 20 65 72 72 6f 72 22  nd of I/O error"
0490: 29 3b 0a 0a 09 69 66 20 28 74 63 6c 45 72 72 6e  );...if (tclErrn
04a0: 6f 20 3d 3d 20 45 41 47 41 49 4e 29 20 7b 0a 09  o == EAGAIN) {..
04b0: 20 20 20 20 64 70 72 69 6e 74 66 28 22 49 74 27      dprintf("It'
04c0: 73 20 45 41 47 41 49 4e 22 29 3b 0a 09 7d 20 65  s EAGAIN");..} e
04d0: 6c 73 65 20 7b 0a 09 20 20 20 20 64 70 72 69 6e  lse {..    dprin
04e0: 74 66 28 22 49 74 27 73 20 61 6e 20 75 6e 65 78  tf("It's an unex
04f0: 70 65 63 74 65 64 20 65 72 72 6f 72 3a 20 25 73  pected error: %s
0500: 2f 25 69 22 2c 20 54 63 6c 5f 45 72 72 6e 6f 4d  /%i", Tcl_ErrnoM
0510: 73 67 28 74 63 6c 45 72 72 6e 6f 29 2c 20 74 63  sg(tclErrno), tc
0520: 6c 45 72 72 6e 6f 29 3b 0a 09 7d 0a 0a 20 20 20  lErrno);..}..   
0530: 20 7d 20 65 6c 73 65 20 7b 0a 09 64 70 72 69 6e   } else {..dprin
0540: 74 66 28 22 53 75 63 63 65 73 73 66 75 6c 6c 79  tf("Successfully
0550: 20 77 72 6f 74 65 20 25 22 20 54 43 4c 5f 53 49   wrote %" TCL_SI
0560: 5a 45 5f 4d 4f 44 49 46 49 45 52 20 22 64 20 62  ZE_MODIFIER "d b
0570: 79 74 65 73 20 6f 66 20 64 61 74 61 22 2c 20 72  ytes of data", r
0580: 65 74 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20  et);.    }..    
0590: 69 66 20 28 72 65 74 20 21 3d 20 2d 31 20 7c 7c  if (ret != -1 ||
05a0: 20 28 72 65 74 20 3d 3d 20 2d 31 20 26 26 20 74   (ret == -1 && t
05b0: 63 6c 45 72 72 6e 6f 20 3d 3d 20 45 41 47 41 49  clErrno == EAGAI
05c0: 4e 29 29 20 7b 0a 09 69 66 20 28 42 49 4f 5f 73  N)) {..if (BIO_s
05d0: 68 6f 75 6c 64 5f 72 65 61 64 28 62 69 6f 29 29  hould_read(bio))
05e0: 20 7b 0a 09 20 20 20 20 64 70 72 69 6e 74 66 28   {..    dprintf(
05f0: 22 53 65 74 74 69 6e 67 20 73 68 6f 75 6c 64 20  "Setting should 
0600: 72 65 74 72 79 20 72 65 61 64 20 66 6c 61 67 22  retry read flag"
0610: 29 3b 0a 0a 09 20 20 20 20 42 49 4f 5f 73 65 74  );...    BIO_set
0620: 5f 72 65 74 72 79 5f 72 65 61 64 28 62 69 6f 29  _retry_read(bio)
0630: 3b 0a 09 7d 0a 20 20 20 20 7d 0a 20 20 20 20 72  ;..}.    }.    r
0640: 65 74 75 72 6e 20 28 69 6e 74 29 20 72 65 74 3b  eturn (int) ret;
0650: 0a 7d 0a 0a 2f 2a 20 43 61 6c 6c 65 64 20 62 79  .}../* Called by
0660: 20 53 53 4c 5f 72 65 61 64 28 29 2a 2f 0a 73 74   SSL_read()*/.st
0670: 61 74 69 63 20 69 6e 74 20 42 69 6f 52 65 61 64  atic int BioRead
0680: 28 42 49 4f 20 2a 62 69 6f 2c 20 63 68 61 72 20  (BIO *bio, char 
0690: 2a 62 75 66 2c 20 69 6e 74 20 62 75 66 4c 65 6e  *buf, int bufLen
06a0: 29 20 7b 0a 20 20 20 20 54 63 6c 5f 43 68 61 6e  ) {.    Tcl_Chan
06b0: 6e 65 6c 20 63 68 61 6e 3b 0a 20 20 20 20 54 63  nel chan;.    Tc
06c0: 6c 5f 53 69 7a 65 20 72 65 74 20 3d 20 30 3b 0a  l_Size ret = 0;.
06d0: 20 20 20 20 69 6e 74 20 74 63 6c 45 6f 66 43 68      int tclEofCh
06e0: 61 6e 2c 20 74 63 6c 45 72 72 6e 6f 3b 0a 0a 20  an, tclErrno;.. 
06f0: 20 20 20 63 68 61 6e 20 3d 20 54 6c 73 5f 47 65     chan = Tls_Ge
0700: 74 50 61 72 65 6e 74 28 28 53 74 61 74 65 20 2a  tParent((State *
0710: 29 20 42 49 4f 5f 67 65 74 5f 64 61 74 61 28 62  ) BIO_get_data(b
0720: 69 6f 29 2c 20 30 29 3b 0a 0a 20 20 20 20 64 70  io), 0);..    dp
0730: 72 69 6e 74 66 28 22 5b 63 68 61 6e 3d 25 70 5d  rintf("[chan=%p]
0740: 20 42 69 6f 52 65 61 64 28 25 70 2c 20 3c 62 75   BioRead(%p, <bu
0750: 66 3e 2c 20 25 64 29 22 2c 20 28 76 6f 69 64 20  f>, %d)", (void 
0760: 2a 29 20 63 68 61 6e 2c 20 28 76 6f 69 64 20 2a  *) chan, (void *
0770: 29 20 62 69 6f 2c 20 62 75 66 4c 65 6e 29 3b 0a  ) bio, bufLen);.
0780: 0a 20 20 20 20 69 66 20 28 62 75 66 20 3d 3d 20  .    if (buf == 
0790: 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 75 72 6e 20  NULL) {..return 
07a0: 30 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 72 65  0;.    }..    re
07b0: 74 20 3d 20 54 63 6c 5f 52 65 61 64 52 61 77 28  t = Tcl_ReadRaw(
07c0: 63 68 61 6e 2c 20 62 75 66 2c 20 28 54 63 6c 5f  chan, buf, (Tcl_
07d0: 53 69 7a 65 29 20 62 75 66 4c 65 6e 29 3b 0a 0a  Size) bufLen);..
07e0: 20 20 20 20 74 63 6c 45 6f 66 43 68 61 6e 20 3d      tclEofChan =
07f0: 20 54 63 6c 5f 45 6f 66 28 63 68 61 6e 29 3b 0a   Tcl_Eof(chan);.
0800: 20 20 20 20 74 63 6c 45 72 72 6e 6f 20 3d 20 54      tclErrno = T
0810: 63 6c 5f 47 65 74 45 72 72 6e 6f 28 29 3b 0a 0a  cl_GetErrno();..
0820: 20 20 20 20 64 70 72 69 6e 74 66 28 22 5b 63 68      dprintf("[ch
0830: 61 6e 3d 25 70 5d 20 42 69 6f 52 65 61 64 28 25  an=%p] BioRead(%
0840: 64 29 20 2d 3e 20 25 22 20 54 43 4c 5f 53 49 5a  d) -> %" TCL_SIZ
0850: 45 5f 4d 4f 44 49 46 49 45 52 20 22 64 20 5b 74  E_MODIFIER "d [t
0860: 63 6c 45 6f 66 3d 25 64 3b 20 74 63 6c 45 72 72  clEof=%d; tclErr
0870: 6e 6f 3d 25 64 5d 22 2c 0a 09 28 76 6f 69 64 20  no=%d]",..(void 
0880: 2a 29 20 63 68 61 6e 2c 20 62 75 66 4c 65 6e 2c  *) chan, bufLen,
0890: 20 72 65 74 2c 20 74 63 6c 45 6f 66 43 68 61 6e   ret, tclEofChan
08a0: 2c 20 74 63 6c 45 72 72 6e 6f 29 3b 0a 0a 20 20  , tclErrno);..  
08b0: 20 20 42 49 4f 5f 63 6c 65 61 72 5f 66 6c 61 67    BIO_clear_flag
08c0: 73 28 62 69 6f 2c 20 42 49 4f 5f 46 4c 41 47 53  s(bio, BIO_FLAGS
08d0: 5f 52 45 41 44 20 7c 20 42 49 4f 5f 46 4c 41 47  _READ | BIO_FLAG
08e0: 53 5f 53 48 4f 55 4c 44 5f 52 45 54 52 59 29 3b  S_SHOULD_RETRY);
08f0: 0a 0a 20 20 20 20 69 66 20 28 74 63 6c 45 6f 66  ..    if (tclEof
0900: 43 68 61 6e 20 26 26 20 72 65 74 20 3c 3d 20 30  Chan && ret <= 0
0910: 29 20 7b 0a 09 64 70 72 69 6e 74 66 28 22 47 6f  ) {..dprintf("Go
0920: 74 20 45 4f 46 20 77 68 69 6c 65 20 72 65 61 64  t EOF while read
0930: 69 6e 67 2c 20 72 65 74 75 72 6e 69 6e 67 20 61  ing, returning a
0940: 20 43 6f 6e 6e 65 63 74 69 6f 6e 20 52 65 73 65   Connection Rese
0950: 74 20 65 72 72 6f 72 20 77 68 69 63 68 20 6d 61  t error which ma
0960: 70 73 20 74 6f 20 53 6f 66 74 20 45 4f 46 22 29  ps to Soft EOF")
0970: 3b 0a 09 54 63 6c 5f 53 65 74 45 72 72 6e 6f 28  ;..Tcl_SetErrno(
0980: 45 43 4f 4e 4e 52 45 53 45 54 29 3b 0a 09 72 65  ECONNRESET);..re
0990: 74 20 3d 20 30 3b 0a 0a 20 20 20 20 7d 20 65 6c  t = 0;..    } el
09a0: 73 65 20 69 66 20 28 72 65 74 20 3d 3d 20 30 29  se if (ret == 0)
09b0: 20 7b 0a 09 64 70 72 69 6e 74 66 28 22 47 6f 74   {..dprintf("Got
09c0: 20 30 20 66 72 6f 6d 20 54 63 6c 5f 52 65 61 64   0 from Tcl_Read
09d0: 20 6f 72 20 54 63 6c 5f 52 65 61 64 52 61 77 2c   or Tcl_ReadRaw,
09e0: 20 61 6e 64 20 45 4f 46 20 69 73 20 6e 6f 74 20   and EOF is not 
09f0: 73 65 74 3b 20 72 65 74 20 3d 20 30 22 29 3b 0a  set; ret = 0");.
0a00: 09 64 70 72 69 6e 74 66 28 22 53 65 74 74 69 6e  .dprintf("Settin
0a10: 67 20 72 65 74 72 79 20 72 65 61 64 20 66 6c 61  g retry read fla
0a20: 67 22 29 3b 0a 09 42 49 4f 5f 73 65 74 5f 72 65  g");..BIO_set_re
0a30: 74 72 79 5f 72 65 61 64 28 62 69 6f 29 3b 0a 0a  try_read(bio);..
0a40: 20 20 20 20 7d 20 65 6c 73 65 20 69 66 20 28 72      } else if (r
0a50: 65 74 20 3c 20 30 29 20 7b 0a 09 64 70 72 69 6e  et < 0) {..dprin
0a60: 74 66 28 22 57 65 20 67 6f 74 20 73 6f 6d 65 20  tf("We got some 
0a70: 6b 69 6e 64 20 6f 66 20 49 2f 4f 20 65 72 72 6f  kind of I/O erro
0a80: 72 22 29 3b 0a 0a 09 69 66 20 28 74 63 6c 45 72  r");...if (tclEr
0a90: 72 6e 6f 20 3d 3d 20 45 41 47 41 49 4e 29 20 7b  rno == EAGAIN) {
0aa0: 0a 09 20 20 20 20 64 70 72 69 6e 74 66 28 22 49  ..    dprintf("I
0ab0: 74 27 73 20 45 41 47 41 49 4e 22 29 3b 0a 09 7d  t's EAGAIN");..}
0ac0: 20 65 6c 73 65 20 7b 0a 09 20 20 20 20 64 70 72   else {..    dpr
0ad0: 69 6e 74 66 28 22 49 74 27 73 20 61 6e 20 75 6e  intf("It's an un
0ae0: 65 78 70 65 63 74 65 64 20 65 72 72 6f 72 3a 20  expected error: 
0af0: 25 73 2f 25 69 22 2c 20 54 63 6c 5f 45 72 72 6e  %s/%i", Tcl_Errn
0b00: 6f 4d 73 67 28 74 63 6c 45 72 72 6e 6f 29 2c 20  oMsg(tclErrno), 
0b10: 74 63 6c 45 72 72 6e 6f 29 3b 0a 09 7d 0a 0a 20  tclErrno);..}.. 
0b20: 20 20 20 7d 20 65 6c 73 65 20 7b 0a 09 64 70 72     } else {..dpr
0b30: 69 6e 74 66 28 22 53 75 63 63 65 73 73 66 75 6c  intf("Successful
0b40: 6c 79 20 72 65 61 64 20 25 22 20 54 43 4c 5f 53  ly read %" TCL_S
0b50: 49 5a 45 5f 4d 4f 44 49 46 49 45 52 20 22 64 20  IZE_MODIFIER "d 
0b60: 62 79 74 65 73 20 6f 66 20 64 61 74 61 22 2c 20  bytes of data", 
0b70: 72 65 74 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20  ret);.    }..   
0b80: 20 69 66 20 28 72 65 74 20 21 3d 20 2d 31 20 7c   if (ret != -1 |
0b90: 7c 20 28 72 65 74 20 3d 3d 20 2d 31 20 26 26 20  | (ret == -1 && 
0ba0: 74 63 6c 45 72 72 6e 6f 20 3d 3d 20 45 41 47 41  tclErrno == EAGA
0bb0: 49 4e 29 29 20 7b 0a 09 69 66 20 28 42 49 4f 5f  IN)) {..if (BIO_
0bc0: 73 68 6f 75 6c 64 5f 77 72 69 74 65 28 62 69 6f  should_write(bio
0bd0: 29 29 20 7b 0a 09 20 20 20 20 64 70 72 69 6e 74  )) {..    dprint
0be0: 66 28 22 53 65 74 74 69 6e 67 20 73 68 6f 75 6c  f("Setting shoul
0bf0: 64 20 72 65 74 72 79 20 77 72 69 74 65 20 66 6c  d retry write fl
0c00: 61 67 22 29 3b 0a 0a 09 20 20 20 20 42 49 4f 5f  ag");...    BIO_
0c10: 73 65 74 5f 72 65 74 72 79 5f 77 72 69 74 65 28  set_retry_write(
0c20: 62 69 6f 29 3b 0a 09 7d 0a 20 20 20 20 7d 0a 0a  bio);..}.    }..
0c30: 20 20 20 20 64 70 72 69 6e 74 66 28 22 42 69 6f      dprintf("Bio
0c40: 52 65 61 64 28 25 70 2c 20 3c 62 75 66 3e 2c 20  Read(%p, <buf>, 
0c50: 25 64 29 20 5b 25 70 5d 20 72 65 74 75 72 6e 69  %d) [%p] returni
0c60: 6e 67 20 25 22 20 54 43 4c 5f 53 49 5a 45 5f 4d  ng %" TCL_SIZE_M
0c70: 4f 44 49 46 49 45 52 20 22 64 22 2c 20 28 76 6f  ODIFIER "d", (vo
0c80: 69 64 20 2a 29 20 62 69 6f 2c 0a 09 62 75 66 4c  id *) bio,..bufL
0c90: 65 6e 2c 20 28 76 6f 69 64 20 2a 29 20 63 68 61  en, (void *) cha
0ca0: 6e 2c 20 72 65 74 29 3b 0a 0a 20 20 20 20 72 65  n, ret);..    re
0cb0: 74 75 72 6e 20 28 69 6e 74 29 20 72 65 74 3b 0a  turn (int) ret;.
0cc0: 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 42 69  }..static int Bi
0cd0: 6f 50 75 74 73 28 42 49 4f 20 2a 62 69 6f 2c 20  oPuts(BIO *bio, 
0ce0: 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 74 72 29  const char *str)
0cf0: 20 7b 0a 20 20 20 20 64 70 72 69 6e 74 66 28 22   {.    dprintf("
0d00: 42 69 6f 50 75 74 73 28 25 70 2c 20 3c 73 74 72  BioPuts(%p, <str
0d10: 69 6e 67 3a 25 70 3e 29 20 63 61 6c 6c 65 64 22  ing:%p>) called"
0d20: 2c 20 62 69 6f 2c 20 73 74 72 29 3b 0a 0a 20 20  , bio, str);..  
0d30: 20 20 72 65 74 75 72 6e 20 42 69 6f 57 72 69 74    return BioWrit
0d40: 65 28 62 69 6f 2c 20 73 74 72 2c 20 28 69 6e 74  e(bio, str, (int
0d50: 29 20 73 74 72 6c 65 6e 28 73 74 72 29 29 3b 0a  ) strlen(str));.
0d60: 7d 0a 0a 73 74 61 74 69 63 20 6c 6f 6e 67 20 42  }..static long B
0d70: 69 6f 43 74 72 6c 28 42 49 4f 20 2a 62 69 6f 2c  ioCtrl(BIO *bio,
0d80: 20 69 6e 74 20 63 6d 64 2c 20 6c 6f 6e 67 20 6e   int cmd, long n
0d90: 75 6d 2c 20 76 6f 69 64 20 2a 70 74 72 29 20 7b  um, void *ptr) {
0da0: 0a 20 20 20 20 54 63 6c 5f 43 68 61 6e 6e 65 6c  .    Tcl_Channel
0db0: 20 63 68 61 6e 3b 0a 20 20 20 20 6c 6f 6e 67 20   chan;.    long 
0dc0: 72 65 74 20 3d 20 31 3b 0a 0a 20 20 20 20 63 68  ret = 1;..    ch
0dd0: 61 6e 20 3d 20 54 6c 73 5f 47 65 74 50 61 72 65  an = Tls_GetPare
0de0: 6e 74 28 28 53 74 61 74 65 20 2a 29 20 42 49 4f  nt((State *) BIO
0df0: 5f 67 65 74 5f 64 61 74 61 28 62 69 6f 29 2c 20  _get_data(bio), 
0e00: 30 29 3b 0a 0a 20 20 20 20 64 70 72 69 6e 74 66  0);..    dprintf
0e10: 28 22 42 69 6f 43 74 72 6c 28 25 70 2c 20 30 78  ("BioCtrl(%p, 0x
0e20: 25 78 2c 20 30 78 25 6c 78 2c 20 25 70 29 22 2c  %x, 0x%lx, %p)",
0e30: 20 28 76 6f 69 64 20 2a 29 20 62 69 6f 2c 20 63   (void *) bio, c
0e40: 6d 64 2c 20 6e 75 6d 2c 20 70 74 72 29 3b 0a 0a  md, num, ptr);..
0e50: 20 20 20 20 73 77 69 74 63 68 20 28 63 6d 64 29      switch (cmd)
0e60: 20 7b 0a 09 63 61 73 65 20 42 49 4f 5f 43 54 52   {..case BIO_CTR
0e70: 4c 5f 52 45 53 45 54 3a 0a 09 09 64 70 72 69 6e  L_RESET:...dprin
0e80: 74 66 28 22 47 6f 74 20 42 49 4f 5f 43 54 52 4c  tf("Got BIO_CTRL
0e90: 5f 52 45 53 45 54 22 29 3b 0a 09 09 72 65 74 20  _RESET");...ret 
0ea0: 3d 20 30 3b 0a 09 09 62 72 65 61 6b 3b 0a 09 63  = 0;...break;..c
0eb0: 61 73 65 20 42 49 4f 5f 43 5f 46 49 4c 45 5f 53  ase BIO_C_FILE_S
0ec0: 45 45 4b 3a 0a 09 09 64 70 72 69 6e 74 66 28 22  EEK:...dprintf("
0ed0: 47 6f 74 20 42 49 4f 5f 43 5f 46 49 4c 45 5f 53  Got BIO_C_FILE_S
0ee0: 45 45 4b 22 29 3b 0a 09 09 72 65 74 20 3d 20 30  EEK");...ret = 0
0ef0: 3b 0a 09 09 62 72 65 61 6b 3b 0a 09 63 61 73 65  ;...break;..case
0f00: 20 42 49 4f 5f 43 5f 46 49 4c 45 5f 54 45 4c 4c   BIO_C_FILE_TELL
0f10: 3a 0a 09 09 64 70 72 69 6e 74 66 28 22 47 6f 74  :...dprintf("Got
0f20: 20 42 49 4f 5f 43 5f 46 49 4c 45 5f 54 45 4c 4c   BIO_C_FILE_TELL
0f30: 22 29 3b 0a 09 09 72 65 74 20 3d 20 30 3b 0a 09  ");...ret = 0;..
0f40: 09 62 72 65 61 6b 3b 0a 09 63 61 73 65 20 42 49  .break;..case BI
0f50: 4f 5f 43 54 52 4c 5f 49 4e 46 4f 3a 0a 09 09 64  O_CTRL_INFO:...d
0f60: 70 72 69 6e 74 66 28 22 47 6f 74 20 42 49 4f 5f  printf("Got BIO_
0f70: 43 54 52 4c 5f 49 4e 46 4f 22 29 3b 0a 09 09 72  CTRL_INFO");...r
0f80: 65 74 20 3d 20 31 3b 0a 09 09 62 72 65 61 6b 3b  et = 1;...break;
0f90: 0a 09 63 61 73 65 20 42 49 4f 5f 43 5f 53 45 54  ..case BIO_C_SET
0fa0: 5f 46 44 3a 0a 09 09 64 70 72 69 6e 74 66 28 22  _FD:...dprintf("
0fb0: 55 6e 73 75 70 70 6f 72 74 65 64 20 63 61 6c 6c  Unsupported call
0fc0: 3a 20 42 49 4f 5f 43 5f 53 45 54 5f 46 44 22 29  : BIO_C_SET_FD")
0fd0: 3b 0a 09 09 72 65 74 20 3d 20 2d 31 3b 0a 09 09  ;...ret = -1;...
0fe0: 62 72 65 61 6b 3b 0a 09 63 61 73 65 20 42 49 4f  break;..case BIO
0ff0: 5f 43 5f 47 45 54 5f 46 44 3a 0a 09 09 64 70 72  _C_GET_FD:...dpr
1000: 69 6e 74 66 28 22 55 6e 73 75 70 70 6f 72 74 65  intf("Unsupporte
1010: 64 20 63 61 6c 6c 3a 20 42 49 4f 5f 43 5f 47 45  d call: BIO_C_GE
1020: 54 5f 46 44 22 29 3b 0a 09 09 72 65 74 20 3d 20  T_FD");...ret = 
1030: 2d 31 3b 0a 09 09 62 72 65 61 6b 3b 0a 09 63 61  -1;...break;..ca
1040: 73 65 20 42 49 4f 5f 43 54 52 4c 5f 47 45 54 5f  se BIO_CTRL_GET_
1050: 43 4c 4f 53 45 3a 0a 09 09 64 70 72 69 6e 74 66  CLOSE:...dprintf
1060: 28 22 47 6f 74 20 42 49 4f 5f 43 54 52 4c 5f 43  ("Got BIO_CTRL_C
1070: 4c 4f 53 45 22 29 3b 0a 09 09 72 65 74 20 3d 20  LOSE");...ret = 
1080: 42 49 4f 5f 67 65 74 5f 73 68 75 74 64 6f 77 6e  BIO_get_shutdown
1090: 28 62 69 6f 29 3b 0a 09 09 62 72 65 61 6b 3b 0a  (bio);...break;.
10a0: 09 63 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f 53  .case BIO_CTRL_S
10b0: 45 54 5f 43 4c 4f 53 45 3a 0a 09 09 64 70 72 69  ET_CLOSE:...dpri
10c0: 6e 74 66 28 22 47 6f 74 20 42 49 4f 5f 53 45 54  ntf("Got BIO_SET
10d0: 5f 43 4c 4f 53 45 22 29 3b 0a 09 09 42 49 4f 5f  _CLOSE");...BIO_
10e0: 73 65 74 5f 73 68 75 74 64 6f 77 6e 28 62 69 6f  set_shutdown(bio
10f0: 2c 20 6e 75 6d 29 3b 0a 09 09 62 72 65 61 6b 3b  , num);...break;
1100: 0a 09 63 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f  ..case BIO_CTRL_
1110: 45 4f 46 3a 0a 09 09 64 70 72 69 6e 74 66 28 22  EOF:...dprintf("
1120: 47 6f 74 20 42 49 4f 5f 43 54 52 4c 5f 45 4f 46  Got BIO_CTRL_EOF
1130: 22 29 3b 0a 09 09 72 65 74 20 3d 20 28 28 63 68  ");...ret = ((ch
1140: 61 6e 29 20 3f 20 54 63 6c 5f 45 6f 66 28 63 68  an) ? Tcl_Eof(ch
1150: 61 6e 29 20 3a 20 31 29 3b 0a 09 09 62 72 65 61  an) : 1);...brea
1160: 6b 3b 0a 09 63 61 73 65 20 42 49 4f 5f 43 54 52  k;..case BIO_CTR
1170: 4c 5f 50 45 4e 44 49 4e 47 3a 0a 09 09 64 70 72  L_PENDING:...dpr
1180: 69 6e 74 66 28 22 47 6f 74 20 42 49 4f 5f 43 54  intf("Got BIO_CT
1190: 52 4c 5f 50 45 4e 44 49 4e 47 22 29 3b 0a 09 09  RL_PENDING");...
11a0: 72 65 74 20 3d 20 28 28 63 68 61 6e 29 20 3f 20  ret = ((chan) ? 
11b0: 28 28 54 63 6c 5f 49 6e 70 75 74 42 75 66 66 65  ((Tcl_InputBuffe
11c0: 72 65 64 28 63 68 61 6e 29 20 3f 20 31 20 3a 20  red(chan) ? 1 : 
11d0: 30 29 29 20 3a 20 30 29 3b 0a 09 09 64 70 72 69  0)) : 0);...dpri
11e0: 6e 74 66 28 22 42 49 4f 5f 43 54 52 4c 5f 50 45  ntf("BIO_CTRL_PE
11f0: 4e 44 49 4e 47 28 25 64 29 22 2c 20 28 69 6e 74  NDING(%d)", (int
1200: 29 20 72 65 74 29 3b 0a 09 09 62 72 65 61 6b 3b  ) ret);...break;
1210: 0a 09 63 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f  ..case BIO_CTRL_
1220: 57 50 45 4e 44 49 4e 47 3a 0a 09 09 64 70 72 69  WPENDING:...dpri
1230: 6e 74 66 28 22 47 6f 74 20 42 49 4f 5f 43 54 52  ntf("Got BIO_CTR
1240: 4c 5f 57 50 45 4e 44 49 4e 47 22 29 3b 0a 09 09  L_WPENDING");...
1250: 72 65 74 20 3d 20 30 3b 0a 09 09 62 72 65 61 6b  ret = 0;...break
1260: 3b 0a 09 63 61 73 65 20 42 49 4f 5f 43 54 52 4c  ;..case BIO_CTRL
1270: 5f 44 55 50 3a 0a 09 09 64 70 72 69 6e 74 66 28  _DUP:...dprintf(
1280: 22 47 6f 74 20 42 49 4f 5f 43 54 52 4c 5f 44 55  "Got BIO_CTRL_DU
1290: 50 22 29 3b 0a 09 09 62 72 65 61 6b 3b 0a 09 63  P");...break;..c
12a0: 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f 46 4c 55  ase BIO_CTRL_FLU
12b0: 53 48 3a 0a 09 09 64 70 72 69 6e 74 66 28 22 47  SH:...dprintf("G
12c0: 6f 74 20 42 49 4f 5f 43 54 52 4c 5f 46 4c 55 53  ot BIO_CTRL_FLUS
12d0: 48 22 29 3b 0a 09 09 72 65 74 20 3d 20 28 28 63  H");...ret = ((c
12e0: 68 61 6e 29 20 26 26 20 28 54 63 6c 5f 57 72 69  han) && (Tcl_Wri
12f0: 74 65 52 61 77 28 63 68 61 6e 2c 20 22 22 2c 20  teRaw(chan, "", 
1300: 30 29 20 3e 3d 20 30 29 20 3f 20 31 20 3a 20 2d  0) >= 0) ? 1 : -
1310: 31 29 3b 0a 09 09 64 70 72 69 6e 74 66 28 22 42  1);...dprintf("B
1320: 49 4f 5f 43 54 52 4c 5f 46 4c 55 53 48 20 72 65  IO_CTRL_FLUSH re
1330: 74 75 72 6e 69 6e 67 20 76 61 6c 75 65 20 25 6c  turning value %l
1340: 69 22 2c 20 72 65 74 29 3b 0a 09 09 62 72 65 61  i", ret);...brea
1350: 6b 3b 0a 09 63 61 73 65 20 42 49 4f 5f 43 54 52  k;..case BIO_CTR
1360: 4c 5f 50 55 53 48 3a 0a 09 09 64 70 72 69 6e 74  L_PUSH:...dprint
1370: 66 28 22 47 6f 74 20 42 49 4f 5f 43 54 52 4c 5f  f("Got BIO_CTRL_
1380: 50 55 53 48 22 29 3b 0a 09 09 72 65 74 20 3d 20  PUSH");...ret = 
1390: 30 3b 0a 09 09 62 72 65 61 6b 3b 0a 09 63 61 73  0;...break;..cas
13a0: 65 20 42 49 4f 5f 43 54 52 4c 5f 50 4f 50 3a 0a  e BIO_CTRL_POP:.
13b0: 09 09 64 70 72 69 6e 74 66 28 22 47 6f 74 20 42  ..dprintf("Got B
13c0: 49 4f 5f 43 54 52 4c 5f 50 4f 50 22 29 3b 0a 09  IO_CTRL_POP");..
13d0: 09 72 65 74 20 3d 20 30 3b 0a 09 09 62 72 65 61  .ret = 0;...brea
13e0: 6b 3b 0a 09 63 61 73 65 20 42 49 4f 5f 43 54 52  k;..case BIO_CTR
13f0: 4c 5f 53 45 54 3a 0a 09 09 64 70 72 69 6e 74 66  L_SET:...dprintf
1400: 28 22 47 6f 74 20 42 49 4f 5f 43 54 52 4c 5f 53  ("Got BIO_CTRL_S
1410: 45 54 22 29 3b 0a 09 09 72 65 74 20 3d 20 30 3b  ET");...ret = 0;
1420: 0a 09 09 62 72 65 61 6b 3b 0a 09 63 61 73 65 20  ...break;..case 
1430: 42 49 4f 5f 43 54 52 4c 5f 47 45 54 20 3a 0a 09  BIO_CTRL_GET :..
1440: 09 64 70 72 69 6e 74 66 28 22 47 6f 74 20 42 49  .dprintf("Got BI
1450: 4f 5f 43 54 52 4c 5f 47 45 54 20 22 29 3b 0a 09  O_CTRL_GET ");..
1460: 09 72 65 74 20 3d 20 30 3b 0a 09 09 62 72 65 61  .ret = 0;...brea
1470: 6b 3b 0a 23 69 66 64 65 66 20 42 49 4f 5f 43 54  k;.#ifdef BIO_CT
1480: 52 4c 5f 47 45 54 5f 4b 54 4c 53 5f 53 45 4e 44  RL_GET_KTLS_SEND
1490: 0a 09 63 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f  ..case BIO_CTRL_
14a0: 47 45 54 5f 4b 54 4c 53 5f 53 45 4e 44 3a 0a 09  GET_KTLS_SEND:..
14b0: 09 64 70 72 69 6e 74 66 28 22 47 6f 74 20 42 49  .dprintf("Got BI
14c0: 4f 5f 43 54 52 4c 5f 47 45 54 5f 4b 54 4c 53 5f  O_CTRL_GET_KTLS_
14d0: 53 45 4e 44 22 29 3b 0a 09 09 72 65 74 20 3d 20  SEND");...ret = 
14e0: 30 3b 0a 09 09 62 72 65 61 6b 3b 0a 23 65 6e 64  0;...break;.#end
14f0: 69 66 0a 23 69 66 64 65 66 20 42 49 4f 5f 43 54  if.#ifdef BIO_CT
1500: 52 4c 5f 47 45 54 5f 4b 54 4c 53 5f 52 45 43 56  RL_GET_KTLS_RECV
1510: 0a 09 63 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f  ..case BIO_CTRL_
1520: 47 45 54 5f 4b 54 4c 53 5f 52 45 43 56 3a 0a 09  GET_KTLS_RECV:..
1530: 09 64 70 72 69 6e 74 66 28 22 47 6f 74 20 42 49  .dprintf("Got BI
1540: 4f 5f 43 54 52 4c 5f 47 45 54 5f 4b 54 4c 53 5f  O_CTRL_GET_KTLS_
1550: 52 45 43 56 22 29 3b 0a 09 09 72 65 74 20 3d 20  RECV");...ret = 
1560: 30 3b 0a 09 09 62 72 65 61 6b 3b 0a 23 65 6e 64  0;...break;.#end
1570: 69 66 0a 09 64 65 66 61 75 6c 74 3a 0a 09 09 64  if..default:...d
1580: 70 72 69 6e 74 66 28 22 47 6f 74 20 75 6e 6b 6e  printf("Got unkn
1590: 6f 77 6e 20 63 6f 6e 74 72 6f 6c 20 63 6f 6d 6d  own control comm
15a0: 61 6e 64 20 28 25 69 29 22 2c 20 63 6d 64 29 3b  and (%i)", cmd);
15b0: 0a 09 09 72 65 74 20 3d 20 30 3b 0a 09 09 62 72  ...ret = 0;...br
15c0: 65 61 6b 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72  eak;.    }.    r
15d0: 65 74 75 72 6e 20 72 65 74 3b 0a 7d 0a 0a 73 74  eturn ret;.}..st
15e0: 61 74 69 63 20 69 6e 74 20 42 69 6f 4e 65 77 28  atic int BioNew(
15f0: 42 49 4f 20 2a 62 69 6f 29 20 7b 0a 20 20 20 20  BIO *bio) {.    
1600: 64 70 72 69 6e 74 66 28 22 42 69 6f 4e 65 77 28  dprintf("BioNew(
1610: 25 70 29 20 63 61 6c 6c 65 64 22 2c 20 62 69 6f  %p) called", bio
1620: 29 3b 0a 0a 20 20 20 20 42 49 4f 5f 73 65 74 5f  );..    BIO_set_
1630: 69 6e 69 74 28 62 69 6f 2c 20 30 29 3b 0a 20 20  init(bio, 0);.  
1640: 20 20 42 49 4f 5f 73 65 74 5f 64 61 74 61 28 62    BIO_set_data(b
1650: 69 6f 2c 20 4e 55 4c 4c 29 3b 0a 20 20 20 20 42  io, NULL);.    B
1660: 49 4f 5f 63 6c 65 61 72 5f 66 6c 61 67 73 28 62  IO_clear_flags(b
1670: 69 6f 2c 20 2d 31 29 3b 0a 20 20 20 20 72 65 74  io, -1);.    ret
1680: 75 72 6e 20 31 3b 0a 7d 0a 0a 73 74 61 74 69 63  urn 1;.}..static
1690: 20 69 6e 74 20 42 69 6f 46 72 65 65 28 42 49 4f   int BioFree(BIO
16a0: 20 2a 62 69 6f 29 20 7b 0a 20 20 20 20 69 66 20   *bio) {.    if 
16b0: 28 62 69 6f 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a  (bio == NULL) {.
16c0: 09 72 65 74 75 72 6e 20 30 3b 0a 20 20 20 20 7d  .return 0;.    }
16d0: 0a 0a 20 20 20 20 64 70 72 69 6e 74 66 28 22 42  ..    dprintf("B
16e0: 69 6f 46 72 65 65 28 25 70 29 20 63 61 6c 6c 65  ioFree(%p) calle
16f0: 64 22 2c 20 62 69 6f 29 3b 0a 0a 20 20 20 20 69  d", bio);..    i
1700: 66 20 28 42 49 4f 5f 67 65 74 5f 73 68 75 74 64  f (BIO_get_shutd
1710: 6f 77 6e 28 62 69 6f 29 29 20 7b 0a 09 69 66 20  own(bio)) {..if 
1720: 28 42 49 4f 5f 67 65 74 5f 69 6e 69 74 28 62 69  (BIO_get_init(bi
1730: 6f 29 29 20 7b 0a 09 20 20 20 20 2f 2a 73 68 75  o)) {..    /*shu
1740: 74 64 6f 77 6e 28 62 69 6f 2d 3e 6e 75 6d 2c 20  tdown(bio->num, 
1750: 32 29 20 2a 2f 0a 09 20 20 20 20 2f 2a 63 6c 6f  2) */..    /*clo
1760: 73 65 73 6f 63 6b 65 74 28 62 69 6f 2d 3e 6e 75  sesocket(bio->nu
1770: 6d 29 20 2a 2f 0a 09 7d 0a 0a 09 42 49 4f 5f 73  m) */..}...BIO_s
1780: 65 74 5f 69 6e 69 74 28 62 69 6f 2c 20 30 29 3b  et_init(bio, 0);
1790: 0a 09 42 49 4f 5f 63 6c 65 61 72 5f 66 6c 61 67  ..BIO_clear_flag
17a0: 73 28 62 69 6f 2c 20 2d 31 29 3b 0a 20 20 20 20  s(bio, -1);.    
17b0: 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 31 3b 0a  }.    return 1;.
17c0: 7d 0a 0a 42 49 4f 20 2a 42 49 4f 5f 6e 65 77 5f  }..BIO *BIO_new_
17d0: 74 63 6c 28 53 74 61 74 65 20 2a 73 74 61 74 65  tcl(State *state
17e0: 50 74 72 2c 20 69 6e 74 20 66 6c 61 67 73 29 20  Ptr, int flags) 
17f0: 7b 0a 20 20 20 20 42 49 4f 20 2a 62 69 6f 3b 0a  {.    BIO *bio;.
1800: 20 20 20 20 73 74 61 74 69 63 20 42 49 4f 5f 4d      static BIO_M
1810: 45 54 48 4f 44 20 2a 42 69 6f 4d 65 74 68 6f 64  ETHOD *BioMethod
1820: 73 20 3d 20 4e 55 4c 4c 3b 0a 23 69 66 64 65 66  s = NULL;.#ifdef
1830: 20 54 43 4c 54 4c 53 5f 53 53 4c 5f 55 53 45 5f   TCLTLS_SSL_USE_
1840: 46 41 53 54 50 41 54 48 0a 20 20 20 20 54 63 6c  FASTPATH.    Tcl
1850: 5f 43 68 61 6e 6e 65 6c 20 70 61 72 65 6e 74 43  _Channel parentC
1860: 68 61 6e 6e 65 6c 3b 0a 20 20 20 20 63 6f 6e 73  hannel;.    cons
1870: 74 20 54 63 6c 5f 43 68 61 6e 6e 65 6c 54 79 70  t Tcl_ChannelTyp
1880: 65 20 2a 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c  e *parentChannel
1890: 54 79 70 65 3b 0a 20 20 20 20 76 6f 69 64 20 2a  Type;.    void *
18a0: 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c 46 64 49  parentChannelFdI
18b0: 6e 5f 70 2c 20 2a 70 61 72 65 6e 74 43 68 61 6e  n_p, *parentChan
18c0: 6e 65 6c 46 64 4f 75 74 5f 70 3b 0a 20 20 20 20  nelFdOut_p;.    
18d0: 69 6e 74 20 70 61 72 65 6e 74 43 68 61 6e 6e 65  int parentChanne
18e0: 6c 46 64 49 6e 2c 20 70 61 72 65 6e 74 43 68 61  lFdIn, parentCha
18f0: 6e 6e 65 6c 46 64 4f 75 74 2c 20 70 61 72 65 6e  nnelFdOut, paren
1900: 74 43 68 61 6e 6e 65 6c 46 64 3b 0a 20 20 20 20  tChannelFd;.    
1910: 69 6e 74 20 76 61 6c 69 64 50 61 72 65 6e 74 43  int validParentC
1920: 68 61 6e 6e 65 6c 46 64 3b 0a 20 20 20 20 69 6e  hannelFd;.    in
1930: 74 20 74 63 6c 47 65 74 43 68 61 6e 6e 65 6c 48  t tclGetChannelH
1940: 61 6e 64 6c 65 52 65 74 3b 0a 23 65 6e 64 69 66  andleRet;.#endif
1950: 0a 0a 20 20 20 20 64 70 72 69 6e 74 66 28 22 42  ..    dprintf("B
1960: 49 4f 5f 6e 65 77 5f 74 63 6c 28 29 20 63 61 6c  IO_new_tcl() cal
1970: 6c 65 64 22 29 3b 0a 0a 20 20 20 20 69 66 20 28  led");..    if (
1980: 42 69 6f 4d 65 74 68 6f 64 73 20 3d 3d 20 4e 55  BioMethods == NU
1990: 4c 4c 29 20 7b 0a 09 42 69 6f 4d 65 74 68 6f 64  LL) {..BioMethod
19a0: 73 20 3d 20 42 49 4f 5f 6d 65 74 68 5f 6e 65 77  s = BIO_meth_new
19b0: 28 42 49 4f 5f 54 59 50 45 5f 54 43 4c 2c 20 22  (BIO_TYPE_TCL, "
19c0: 74 63 6c 22 29 3b 0a 09 42 49 4f 5f 6d 65 74 68  tcl");..BIO_meth
19d0: 5f 73 65 74 5f 77 72 69 74 65 28 42 69 6f 4d 65  _set_write(BioMe
19e0: 74 68 6f 64 73 2c 20 42 69 6f 57 72 69 74 65 29  thods, BioWrite)
19f0: 3b 0a 09 42 49 4f 5f 6d 65 74 68 5f 73 65 74 5f  ;..BIO_meth_set_
1a00: 72 65 61 64 28 42 69 6f 4d 65 74 68 6f 64 73 2c  read(BioMethods,
1a10: 20 42 69 6f 52 65 61 64 29 3b 0a 09 42 49 4f 5f   BioRead);..BIO_
1a20: 6d 65 74 68 5f 73 65 74 5f 70 75 74 73 28 42 69  meth_set_puts(Bi
1a30: 6f 4d 65 74 68 6f 64 73 2c 20 42 69 6f 50 75 74  oMethods, BioPut
1a40: 73 29 3b 0a 09 42 49 4f 5f 6d 65 74 68 5f 73 65  s);..BIO_meth_se
1a50: 74 5f 63 74 72 6c 28 42 69 6f 4d 65 74 68 6f 64  t_ctrl(BioMethod
1a60: 73 2c 20 42 69 6f 43 74 72 6c 29 3b 0a 09 42 49  s, BioCtrl);..BI
1a70: 4f 5f 6d 65 74 68 5f 73 65 74 5f 63 72 65 61 74  O_meth_set_creat
1a80: 65 28 42 69 6f 4d 65 74 68 6f 64 73 2c 20 42 69  e(BioMethods, Bi
1a90: 6f 4e 65 77 29 3b 0a 09 42 49 4f 5f 6d 65 74 68  oNew);..BIO_meth
1aa0: 5f 73 65 74 5f 64 65 73 74 72 6f 79 28 42 69 6f  _set_destroy(Bio
1ab0: 4d 65 74 68 6f 64 73 2c 20 42 69 6f 46 72 65 65  Methods, BioFree
1ac0: 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 69 66  );.    }..    if
1ad0: 20 28 73 74 61 74 65 50 74 72 20 3d 3d 20 4e 55   (statePtr == NU
1ae0: 4c 4c 29 20 7b 0a 09 64 70 72 69 6e 74 66 28 22  LL) {..dprintf("
1af0: 41 73 6b 65 64 20 74 6f 20 73 65 74 75 70 20 61  Asked to setup a
1b00: 20 4e 55 4c 4c 20 73 74 61 74 65 2c 20 6a 75 73   NULL state, jus
1b10: 74 20 63 72 65 61 74 69 6e 67 20 74 68 65 20 69  t creating the i
1b20: 6e 69 74 69 61 6c 20 63 6f 6e 66 69 67 75 72 61  nitial configura
1b30: 74 69 6f 6e 22 29 3b 0a 0a 09 72 65 74 75 72 6e  tion");...return
1b40: 20 4e 55 4c 4c 3b 0a 20 20 20 20 7d 0a 0a 23 69   NULL;.    }..#i
1b50: 66 64 65 66 20 54 43 4c 54 4c 53 5f 53 53 4c 5f  fdef TCLTLS_SSL_
1b60: 55 53 45 5f 46 41 53 54 50 41 54 48 0a 20 20 20  USE_FASTPATH.   
1b70: 20 2f 2a 0a 20 20 20 20 20 2a 20 49 66 20 74 68   /*.     * If th
1b80: 65 20 63 68 61 6e 6e 65 6c 20 63 61 6e 20 62 65  e channel can be
1b90: 20 6d 61 70 70 65 64 20 62 61 63 6b 20 74 6f 20   mapped back to 
1ba0: 61 20 66 69 6c 65 20 64 65 73 63 72 69 70 74 6f  a file descripto
1bb0: 72 2c 20 6a 75 73 74 20 75 73 65 20 74 68 65 20  r, just use the 
1bc0: 66 69 6c 65 20 64 65 73 63 72 69 70 74 6f 72 0a  file descriptor.
1bd0: 20 20 20 20 20 2a 20 77 69 74 68 20 74 68 65 20       * with the 
1be0: 53 53 4c 20 6c 69 62 72 61 72 79 20 73 69 6e 63  SSL library sinc
1bf0: 65 20 69 74 20 77 69 6c 6c 20 6c 69 6b 65 6c 79  e it will likely
1c00: 20 62 65 20 6f 70 74 69 6d 69 7a 65 64 20 66 6f   be optimized fo
1c10: 72 20 74 68 69 73 2e 0a 20 20 20 20 20 2a 2f 0a  r this..     */.
1c20: 20 20 20 20 70 61 72 65 6e 74 43 68 61 6e 6e 65      parentChanne
1c30: 6c 20 3d 20 54 6c 73 5f 47 65 74 50 61 72 65 6e  l = Tls_GetParen
1c40: 74 28 73 74 61 74 65 50 74 72 2c 20 30 29 3b 0a  t(statePtr, 0);.
1c50: 20 20 20 20 70 61 72 65 6e 74 43 68 61 6e 6e 65      parentChanne
1c60: 6c 54 79 70 65 20 3d 20 54 63 6c 5f 47 65 74 43  lType = Tcl_GetC
1c70: 68 61 6e 6e 65 6c 54 79 70 65 28 70 61 72 65 6e  hannelType(paren
1c80: 74 43 68 61 6e 6e 65 6c 29 3b 0a 0a 20 20 20 20  tChannel);..    
1c90: 76 61 6c 69 64 50 61 72 65 6e 74 43 68 61 6e 6e  validParentChann
1ca0: 65 6c 46 64 20 3d 20 30 3b 0a 20 20 20 20 69 66  elFd = 0;.    if
1cb0: 20 28 73 74 72 63 6d 70 28 70 61 72 65 6e 74 43   (strcmp(parentC
1cc0: 68 61 6e 6e 65 6c 54 79 70 65 2d 3e 74 79 70 65  hannelType->type
1cd0: 4e 61 6d 65 2c 20 22 74 63 70 22 29 20 3d 3d 20  Name, "tcp") == 
1ce0: 30 29 20 7b 0a 09 74 63 6c 47 65 74 43 68 61 6e  0) {..tclGetChan
1cf0: 6e 65 6c 48 61 6e 64 6c 65 52 65 74 20 3d 20 54  nelHandleRet = T
1d00: 63 6c 5f 47 65 74 43 68 61 6e 6e 65 6c 48 61 6e  cl_GetChannelHan
1d10: 64 6c 65 28 70 61 72 65 6e 74 43 68 61 6e 6e 65  dle(parentChanne
1d20: 6c 2c 20 54 43 4c 5f 52 45 41 44 41 42 4c 45 2c  l, TCL_READABLE,
1d30: 20 28 43 6c 69 65 6e 74 44 61 74 61 29 20 26 70   (ClientData) &p
1d40: 61 72 65 6e 74 43 68 61 6e 6e 65 6c 46 64 49 6e  arentChannelFdIn
1d50: 5f 70 29 3b 0a 09 69 66 20 28 74 63 6c 47 65 74  _p);..if (tclGet
1d60: 43 68 61 6e 6e 65 6c 48 61 6e 64 6c 65 52 65 74  ChannelHandleRet
1d70: 20 3d 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 20   == TCL_OK) {.. 
1d80: 20 20 20 74 63 6c 47 65 74 43 68 61 6e 6e 65 6c     tclGetChannel
1d90: 48 61 6e 64 6c 65 52 65 74 20 3d 20 54 63 6c 5f  HandleRet = Tcl_
1da0: 47 65 74 43 68 61 6e 6e 65 6c 48 61 6e 64 6c 65  GetChannelHandle
1db0: 28 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c 2c 20  (parentChannel, 
1dc0: 54 43 4c 5f 57 52 49 54 41 42 4c 45 2c 20 28 43  TCL_WRITABLE, (C
1dd0: 6c 69 65 6e 74 44 61 74 61 29 20 26 70 61 72 65  lientData) &pare
1de0: 6e 74 43 68 61 6e 6e 65 6c 46 64 4f 75 74 5f 70  ntChannelFdOut_p
1df0: 29 3b 0a 09 20 20 20 20 69 66 20 28 74 63 6c 47  );..    if (tclG
1e00: 65 74 43 68 61 6e 6e 65 6c 48 61 6e 64 6c 65 52  etChannelHandleR
1e10: 65 74 20 3d 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a  et == TCL_OK) {.
1e20: 09 09 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c 46  ..parentChannelF
1e30: 64 49 6e 20 3d 20 50 54 52 32 49 4e 54 28 70 61  dIn = PTR2INT(pa
1e40: 72 65 6e 74 43 68 61 6e 6e 65 6c 46 64 49 6e 5f  rentChannelFdIn_
1e50: 70 29 3b 0a 09 09 70 61 72 65 6e 74 43 68 61 6e  p);...parentChan
1e60: 6e 65 6c 46 64 4f 75 74 20 3d 20 50 54 52 32 49  nelFdOut = PTR2I
1e70: 4e 54 28 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c  NT(parentChannel
1e80: 46 64 4f 75 74 5f 70 29 3b 0a 09 09 69 66 20 28  FdOut_p);...if (
1e90: 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c 46 64 49  parentChannelFdI
1ea0: 6e 20 3d 3d 20 70 61 72 65 6e 74 43 68 61 6e 6e  n == parentChann
1eb0: 65 6c 46 64 4f 75 74 29 20 7b 0a 09 09 20 20 20  elFdOut) {...   
1ec0: 20 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c 46 64   parentChannelFd
1ed0: 20 3d 20 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c   = parentChannel
1ee0: 46 64 49 6e 3b 0a 09 09 20 20 20 20 76 61 6c 69  FdIn;...    vali
1ef0: 64 50 61 72 65 6e 74 43 68 61 6e 6e 65 6c 46 64  dParentChannelFd
1f00: 20 3d 20 31 3b 0a 09 09 7d 0a 09 20 20 20 20 7d   = 1;...}..    }
1f10: 0a 09 7d 0a 20 20 20 20 7d 0a 0a 20 20 20 20 69  ..}.    }..    i
1f20: 66 20 28 76 61 6c 69 64 50 61 72 65 6e 74 43 68  f (validParentCh
1f30: 61 6e 6e 65 6c 46 64 29 20 7b 0a 09 64 70 72 69  annelFd) {..dpri
1f40: 6e 74 66 28 22 57 65 20 66 6f 75 6e 64 20 61 20  ntf("We found a 
1f50: 73 68 6f 72 74 63 75 74 2c 20 74 68 69 73 20 63  shortcut, this c
1f60: 68 61 6e 6e 65 6c 20 69 73 20 62 61 63 6b 65 64  hannel is backed
1f70: 20 62 79 20 61 20 73 6f 63 6b 65 74 3a 20 25 69   by a socket: %i
1f80: 22 2c 20 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c  ", parentChannel
1f90: 46 64 49 6e 29 3b 0a 09 62 69 6f 20 3d 20 42 49  FdIn);..bio = BI
1fa0: 4f 5f 6e 65 77 5f 73 6f 63 6b 65 74 28 70 61 72  O_new_socket(par
1fb0: 65 6e 74 43 68 61 6e 6e 65 6c 46 64 2c 20 66 6c  entChannelFd, fl
1fc0: 61 67 73 29 3b 0a 09 73 74 61 74 65 50 74 72 2d  ags);..statePtr-
1fd0: 3e 66 6c 61 67 73 20 7c 3d 20 54 4c 53 5f 54 43  >flags |= TLS_TC
1fe0: 4c 5f 46 41 53 54 50 41 54 48 3b 0a 09 72 65 74  L_FASTPATH;..ret
1ff0: 75 72 6e 20 62 69 6f 3b 0a 20 20 20 20 7d 0a 0a  urn bio;.    }..
2000: 20 20 20 20 64 70 72 69 6e 74 66 28 22 46 61 6c      dprintf("Fal
2010: 6c 69 6e 67 20 62 61 63 6b 20 74 6f 20 54 63 6c  ling back to Tcl
2020: 20 49 2f 4f 20 66 6f 72 20 74 68 69 73 20 63 68   I/O for this ch
2030: 61 6e 6e 65 6c 22 29 3b 0a 23 65 6e 64 69 66 0a  annel");.#endif.
2040: 0a 20 20 20 20 62 69 6f 20 3d 20 42 49 4f 5f 6e  .    bio = BIO_n
2050: 65 77 28 42 69 6f 4d 65 74 68 6f 64 73 29 3b 0a  ew(BioMethods);.
2060: 20 20 20 20 42 49 4f 5f 73 65 74 5f 64 61 74 61      BIO_set_data
2070: 28 62 69 6f 2c 20 73 74 61 74 65 50 74 72 29 3b  (bio, statePtr);
2080: 0a 20 20 20 20 42 49 4f 5f 73 65 74 5f 73 68 75  .    BIO_set_shu
2090: 74 64 6f 77 6e 28 62 69 6f 2c 20 66 6c 61 67 73  tdown(bio, flags
20a0: 29 3b 0a 20 20 20 20 42 49 4f 5f 73 65 74 5f 69  );.    BIO_set_i
20b0: 6e 69 74 28 62 69 6f 2c 20 31 29 3b 0a 20 20 20  nit(bio, 1);.   
20c0: 20 72 65 74 75 72 6e 20 62 69 6f 3b 0a 7d 0a      return bio;.}.