Hex Artifact Content

Artifact e2553f33f8beb8f0f153a3ba4a0e64daec3b7be65741bbdea10c0704d95534e3:


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: 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 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 62 75 66 4c  , (Tcl_Size)bufL
01f0: 65 6e 29 3b 0a 0a 20 20 20 20 74 63 6c 45 6f 66  en);..    tclEof
0200: 43 68 61 6e 20 3d 20 54 63 6c 5f 45 6f 66 28 63  Chan = Tcl_Eof(c
0210: 68 61 6e 29 3b 0a 20 20 20 20 74 63 6c 45 72 72  han);.    tclErr
0220: 6e 6f 20 3d 20 54 63 6c 5f 47 65 74 45 72 72 6e  no = Tcl_GetErrn
0230: 6f 28 29 3b 0a 0a 20 20 20 20 64 70 72 69 6e 74  o();..    dprint
0240: 66 28 22 5b 63 68 61 6e 3d 25 70 5d 20 42 69 6f  f("[chan=%p] Bio
0250: 57 72 69 74 65 28 25 64 29 20 2d 3e 20 25 22 20  Write(%d) -> %" 
0260: 54 43 4c 5f 53 49 5a 45 5f 4d 4f 44 49 46 49 45  TCL_SIZE_MODIFIE
0270: 52 20 22 64 20 5b 74 63 6c 45 6f 66 3d 25 64 3b  R "d [tclEof=%d;
0280: 20 74 63 6c 45 72 72 6e 6f 3d 25 64 5d 22 2c 0a   tclErrno=%d]",.
0290: 09 20 20 20 20 28 76 6f 69 64 20 2a 29 20 63 68  .    (void *) ch
02a0: 61 6e 2c 20 62 75 66 4c 65 6e 2c 20 72 65 74 2c  an, bufLen, ret,
02b0: 20 74 63 6c 45 6f 66 43 68 61 6e 2c 20 74 63 6c   tclEofChan, tcl
02c0: 45 72 72 6e 6f 29 3b 0a 0a 20 20 20 20 42 49 4f  Errno);..    BIO
02d0: 5f 63 6c 65 61 72 5f 66 6c 61 67 73 28 62 69 6f  _clear_flags(bio
02e0: 2c 20 42 49 4f 5f 46 4c 41 47 53 5f 57 52 49 54  , BIO_FLAGS_WRIT
02f0: 45 20 7c 20 42 49 4f 5f 46 4c 41 47 53 5f 53 48  E | BIO_FLAGS_SH
0300: 4f 55 4c 44 5f 52 45 54 52 59 29 3b 0a 0a 20 20  OULD_RETRY);..  
0310: 20 20 69 66 20 28 74 63 6c 45 6f 66 43 68 61 6e    if (tclEofChan
0320: 20 26 26 20 72 65 74 20 3c 3d 20 30 29 20 7b 0a   && ret <= 0) {.
0330: 09 64 70 72 69 6e 74 66 28 22 47 6f 74 20 45 4f  .dprintf("Got EO
0340: 46 20 77 68 69 6c 65 20 72 65 61 64 69 6e 67 2c  F while reading,
0350: 20 72 65 74 75 72 6e 69 6e 67 20 61 20 43 6f 6e   returning a Con
0360: 6e 65 63 74 69 6f 6e 20 52 65 73 65 74 20 65 72  nection Reset er
0370: 72 6f 72 20 77 68 69 63 68 20 6d 61 70 73 20 74  ror which maps t
0380: 6f 20 53 6f 66 74 20 45 4f 46 22 29 3b 0a 09 54  o Soft EOF");..T
0390: 63 6c 5f 53 65 74 45 72 72 6e 6f 28 45 43 4f 4e  cl_SetErrno(ECON
03a0: 4e 52 45 53 45 54 29 3b 0a 09 72 65 74 20 3d 20  NRESET);..ret = 
03b0: 30 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20 69 66  0;.    } else if
03c0: 20 28 72 65 74 20 3d 3d 20 30 29 20 7b 0a 09 64   (ret == 0) {..d
03d0: 70 72 69 6e 74 66 28 22 47 6f 74 20 30 20 66 72  printf("Got 0 fr
03e0: 6f 6d 20 54 63 6c 5f 57 72 69 74 65 52 61 77 2c  om Tcl_WriteRaw,
03f0: 20 61 6e 64 20 45 4f 46 20 69 73 20 6e 6f 74 20   and EOF is not 
0400: 73 65 74 3b 20 72 65 74 20 3d 20 30 22 29 3b 0a  set; ret = 0");.
0410: 09 64 70 72 69 6e 74 66 28 22 53 65 74 74 69 6e  .dprintf("Settin
0420: 67 20 72 65 74 72 79 20 72 65 61 64 20 66 6c 61  g retry read fla
0430: 67 22 29 3b 0a 09 42 49 4f 5f 73 65 74 5f 72 65  g");..BIO_set_re
0440: 74 72 79 5f 72 65 61 64 28 62 69 6f 29 3b 0a 20  try_read(bio);. 
0450: 20 20 20 7d 20 65 6c 73 65 20 69 66 20 28 72 65     } else if (re
0460: 74 20 3c 20 30 29 20 7b 0a 09 64 70 72 69 6e 74  t < 0) {..dprint
0470: 66 28 22 57 65 20 67 6f 74 20 73 6f 6d 65 20 6b  f("We got some k
0480: 69 6e 64 20 6f 66 20 49 2f 4f 20 65 72 72 6f 72  ind of I/O error
0490: 22 29 3b 0a 0a 09 69 66 20 28 74 63 6c 45 72 72  ");...if (tclErr
04a0: 6e 6f 20 3d 3d 20 45 41 47 41 49 4e 29 20 7b 0a  no == EAGAIN) {.
04b0: 09 20 20 20 20 64 70 72 69 6e 74 66 28 22 49 74  .    dprintf("It
04c0: 27 73 20 45 41 47 41 49 4e 22 29 3b 0a 09 7d 20  's EAGAIN");..} 
04d0: 65 6c 73 65 20 7b 0a 09 20 20 20 20 64 70 72 69  else {..    dpri
04e0: 6e 74 66 28 22 49 74 27 73 20 61 6e 20 75 6e 65  ntf("It's an une
04f0: 78 70 65 63 74 65 64 20 65 72 72 6f 72 3a 20 25  xpected error: %
0500: 73 2f 25 69 22 2c 20 54 63 6c 5f 45 72 72 6e 6f  s/%i", Tcl_Errno
0510: 4d 73 67 28 74 63 6c 45 72 72 6e 6f 29 2c 20 74  Msg(tclErrno), t
0520: 63 6c 45 72 72 6e 6f 29 3b 0a 09 7d 0a 20 20 20  clErrno);..}.   
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 28 28 69 6e 74 29 20 72 65 74 29  eturn((int) ret)
0650: 3b 0a 7d 0a 0a 2f 2a 20 43 61 6c 6c 65 64 20 62  ;.}../* Called b
0660: 79 20 53 53 4c 5f 72 65 61 64 28 29 2a 2f 0a 73  y SSL_read()*/.s
0670: 74 61 74 69 63 20 69 6e 74 20 42 69 6f 52 65 61  tatic int BioRea
0680: 64 28 42 49 4f 20 2a 62 69 6f 2c 20 63 68 61 72  d(BIO *bio, char
0690: 20 2a 62 75 66 2c 20 69 6e 74 20 62 75 66 4c 65   *buf, int bufLe
06a0: 6e 29 20 7b 0a 20 20 20 20 54 63 6c 5f 43 68 61  n) {.    Tcl_Cha
06b0: 6e 6e 65 6c 20 63 68 61 6e 3b 0a 20 20 20 20 54  nnel chan;.    T
06c0: 63 6c 5f 53 69 7a 65 20 72 65 74 20 3d 20 30 3b  cl_Size ret = 0;
06d0: 0a 20 20 20 20 69 6e 74 20 74 63 6c 45 6f 66 43  .    int tclEofC
06e0: 68 61 6e 2c 20 74 63 6c 45 72 72 6e 6f 3b 0a 0a  han, tclErrno;..
06f0: 20 20 20 20 63 68 61 6e 20 3d 20 54 6c 73 5f 47      chan = Tls_G
0700: 65 74 50 61 72 65 6e 74 28 28 53 74 61 74 65 20  etParent((State 
0710: 2a 29 20 42 49 4f 5f 67 65 74 5f 64 61 74 61 28  *) BIO_get_data(
0720: 62 69 6f 29 2c 20 30 29 3b 0a 0a 20 20 20 20 64  bio), 0);..    d
0730: 70 72 69 6e 74 66 28 22 5b 63 68 61 6e 3d 25 70  printf("[chan=%p
0740: 5d 20 42 69 6f 52 65 61 64 28 25 70 2c 20 3c 62  ] BioRead(%p, <b
0750: 75 66 3e 2c 20 25 64 29 22 2c 20 28 76 6f 69 64  uf>, %d)", (void
0760: 20 2a 29 20 63 68 61 6e 2c 20 28 76 6f 69 64 20   *) chan, (void 
0770: 2a 29 20 62 69 6f 2c 20 62 75 66 4c 65 6e 29 3b  *) bio, bufLen);
0780: 0a 0a 20 20 20 20 69 66 20 28 62 75 66 20 3d 3d  ..    if (buf ==
0790: 20 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 75 72 6e   NULL) {..return
07a0: 20 30 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 72   0;.    }..    r
07b0: 65 74 20 3d 20 54 63 6c 5f 52 65 61 64 52 61 77  et = Tcl_ReadRaw
07c0: 28 63 68 61 6e 2c 20 62 75 66 2c 20 28 54 63 6c  (chan, buf, (Tcl
07d0: 5f 53 69 7a 65 29 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 20 20 20 20 28 76  no=%d]",..    (v
0880: 6f 69 64 20 2a 29 20 63 68 61 6e 2c 20 62 75 66  oid *) chan, buf
0890: 4c 65 6e 2c 20 72 65 74 2c 20 74 63 6c 45 6f 66  Len, ret, tclEof
08a0: 43 68 61 6e 2c 20 74 63 6c 45 72 72 6e 6f 29 3b  Chan, tclErrno);
08b0: 0a 0a 20 20 20 20 42 49 4f 5f 63 6c 65 61 72 5f  ..    BIO_clear_
08c0: 66 6c 61 67 73 28 62 69 6f 2c 20 42 49 4f 5f 46  flags(bio, BIO_F
08d0: 4c 41 47 53 5f 52 45 41 44 20 7c 20 42 49 4f 5f  LAGS_READ | BIO_
08e0: 46 4c 41 47 53 5f 53 48 4f 55 4c 44 5f 52 45 54  FLAGS_SHOULD_RET
08f0: 52 59 29 3b 0a 0a 20 20 20 20 69 66 20 28 74 63  RY);..    if (tc
0900: 6c 45 6f 66 43 68 61 6e 20 26 26 20 72 65 74 20  lEofChan && ret 
0910: 3c 3d 20 30 29 20 7b 0a 09 64 70 72 69 6e 74 66  <= 0) {..dprintf
0920: 28 22 47 6f 74 20 45 4f 46 20 77 68 69 6c 65 20  ("Got EOF while 
0930: 72 65 61 64 69 6e 67 2c 20 72 65 74 75 72 6e 69  reading, returni
0940: 6e 67 20 61 20 43 6f 6e 6e 65 63 74 69 6f 6e 20  ng a Connection 
0950: 52 65 73 65 74 20 65 72 72 6f 72 20 77 68 69 63  Reset error whic
0960: 68 20 6d 61 70 73 20 74 6f 20 53 6f 66 74 20 45  h maps to Soft E
0970: 4f 46 22 29 3b 0a 09 54 63 6c 5f 53 65 74 45 72  OF");..Tcl_SetEr
0980: 72 6e 6f 28 45 43 4f 4e 4e 52 45 53 45 54 29 3b  rno(ECONNRESET);
0990: 0a 09 72 65 74 20 3d 20 30 3b 0a 20 20 20 20 7d  ..ret = 0;.    }
09a0: 20 65 6c 73 65 20 69 66 20 28 72 65 74 20 3d 3d   else if (ret ==
09b0: 20 30 29 20 7b 0a 09 64 70 72 69 6e 74 66 28 22   0) {..dprintf("
09c0: 47 6f 74 20 30 20 66 72 6f 6d 20 54 63 6c 5f 52  Got 0 from Tcl_R
09d0: 65 61 64 20 6f 72 20 54 63 6c 5f 52 65 61 64 52  ead or Tcl_ReadR
09e0: 61 77 2c 20 61 6e 64 20 45 4f 46 20 69 73 20 6e  aw, and EOF is n
09f0: 6f 74 20 73 65 74 3b 20 72 65 74 20 3d 20 30 22  ot set; ret = 0"
0a00: 29 3b 0a 09 64 70 72 69 6e 74 66 28 22 53 65 74  );..dprintf("Set
0a10: 74 69 6e 67 20 72 65 74 72 79 20 72 65 61 64 20  ting retry read 
0a20: 66 6c 61 67 22 29 3b 0a 09 42 49 4f 5f 73 65 74  flag");..BIO_set
0a30: 5f 72 65 74 72 79 5f 72 65 61 64 28 62 69 6f 29  _retry_read(bio)
0a40: 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20 69 66 20  ;.    } else if 
0a50: 28 72 65 74 20 3c 20 30 29 20 7b 0a 09 64 70 72  (ret < 0) {..dpr
0a60: 69 6e 74 66 28 22 57 65 20 67 6f 74 20 73 6f 6d  intf("We got som
0a70: 65 20 6b 69 6e 64 20 6f 66 20 49 2f 4f 20 65 72  e kind of I/O er
0a80: 72 6f 72 22 29 3b 0a 0a 09 69 66 20 28 74 63 6c  ror");...if (tcl
0a90: 45 72 72 6e 6f 20 3d 3d 20 45 41 47 41 49 4e 29  Errno == EAGAIN)
0aa0: 20 7b 0a 09 20 20 20 20 64 70 72 69 6e 74 66 28   {..    dprintf(
0ab0: 22 49 74 27 73 20 45 41 47 41 49 4e 22 29 3b 0a  "It's EAGAIN");.
0ac0: 09 7d 20 65 6c 73 65 20 7b 0a 09 20 20 20 20 64  .} else {..    d
0ad0: 70 72 69 6e 74 66 28 22 49 74 27 73 20 61 6e 20  printf("It's an 
0ae0: 75 6e 65 78 70 65 63 74 65 64 20 65 72 72 6f 72  unexpected error
0af0: 3a 20 25 73 2f 25 69 22 2c 20 54 63 6c 5f 45 72  : %s/%i", Tcl_Er
0b00: 72 6e 6f 4d 73 67 28 74 63 6c 45 72 72 6e 6f 29  rnoMsg(tclErrno)
0b10: 2c 20 74 63 6c 45 72 72 6e 6f 29 3b 0a 09 7d 0a  , tclErrno);..}.
0b20: 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a 09 64 70      } else {..dp
0b30: 72 69 6e 74 66 28 22 53 75 63 63 65 73 73 66 75  rintf("Successfu
0b40: 6c 6c 79 20 72 65 61 64 20 25 22 20 54 43 4c 5f  lly read %" TCL_
0b50: 53 49 5a 45 5f 4d 4f 44 49 46 49 45 52 20 22 64  SIZE_MODIFIER "d
0b60: 20 62 79 74 65 73 20 6f 66 20 64 61 74 61 22 2c   bytes of data",
0b70: 20 72 65 74 29 3b 0a 20 20 20 20 7d 0a 0a 20 20   ret);.    }..  
0b80: 20 20 69 66 20 28 72 65 74 20 21 3d 20 2d 31 20    if (ret != -1 
0b90: 7c 7c 20 28 72 65 74 20 3d 3d 20 2d 31 20 26 26  || (ret == -1 &&
0ba0: 20 74 63 6c 45 72 72 6e 6f 20 3d 3d 20 45 41 47   tclErrno == EAG
0bb0: 41 49 4e 29 29 20 7b 0a 09 69 66 20 28 42 49 4f  AIN)) {..if (BIO
0bc0: 5f 73 68 6f 75 6c 64 5f 77 72 69 74 65 28 62 69  _should_write(bi
0bd0: 6f 29 29 20 7b 0a 09 20 20 20 20 64 70 72 69 6e  o)) {..    dprin
0be0: 74 66 28 22 53 65 74 74 69 6e 67 20 73 68 6f 75  tf("Setting shou
0bf0: 6c 64 20 72 65 74 72 79 20 77 72 69 74 65 20 66  ld retry write f
0c00: 6c 61 67 22 29 3b 0a 0a 09 20 20 20 20 42 49 4f  lag");...    BIO
0c10: 5f 73 65 74 5f 72 65 74 72 79 5f 77 72 69 74 65  _set_retry_write
0c20: 28 62 69 6f 29 3b 0a 09 7d 0a 20 20 20 20 7d 0a  (bio);..}.    }.
0c30: 0a 20 20 20 20 64 70 72 69 6e 74 66 28 22 42 69  .    dprintf("Bi
0c40: 6f 52 65 61 64 28 25 70 2c 20 3c 62 75 66 3e 2c  oRead(%p, <buf>,
0c50: 20 25 64 29 20 5b 25 70 5d 20 72 65 74 75 72 6e   %d) [%p] return
0c60: 69 6e 67 20 25 22 20 54 43 4c 5f 53 49 5a 45 5f  ing %" TCL_SIZE_
0c70: 4d 4f 44 49 46 49 45 52 20 22 64 22 2c 0a 09 20  MODIFIER "d",.. 
0c80: 20 20 20 28 76 6f 69 64 20 2a 29 62 69 6f 2c 20     (void *)bio, 
0c90: 62 75 66 4c 65 6e 2c 20 28 76 6f 69 64 20 2a 29  bufLen, (void *)
0ca0: 20 63 68 61 6e 2c 20 72 65 74 29 3b 0a 0a 20 20   chan, ret);..  
0cb0: 20 20 72 65 74 75 72 6e 20 28 69 6e 74 29 72 65    return (int)re
0cc0: 74 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74  t;.}..static int
0cd0: 20 42 69 6f 50 75 74 73 28 42 49 4f 20 2a 62 69   BioPuts(BIO *bi
0ce0: 6f 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 73  o, const char *s
0cf0: 74 72 29 20 7b 0a 20 20 20 20 64 70 72 69 6e 74  tr) {.    dprint
0d00: 66 28 22 42 69 6f 50 75 74 73 28 25 70 2c 20 3c  f("BioPuts(%p, <
0d10: 73 74 72 69 6e 67 3a 25 70 3e 29 20 63 61 6c 6c  string:%p>) call
0d20: 65 64 22 2c 20 62 69 6f 2c 20 73 74 72 29 3b 0a  ed", bio, str);.
0d30: 0a 20 20 20 20 72 65 74 75 72 6e 20 42 69 6f 57  .    return BioW
0d40: 72 69 74 65 28 62 69 6f 2c 20 73 74 72 2c 20 28  rite(bio, str, (
0d50: 69 6e 74 29 20 73 74 72 6c 65 6e 28 73 74 72 29  int) strlen(str)
0d60: 29 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 6c 6f 6e  );.}..static lon
0d70: 67 20 42 69 6f 43 74 72 6c 28 42 49 4f 20 2a 62  g BioCtrl(BIO *b
0d80: 69 6f 2c 20 69 6e 74 20 63 6d 64 2c 20 6c 6f 6e  io, int cmd, lon
0d90: 67 20 6e 75 6d 2c 20 76 6f 69 64 20 2a 70 74 72  g num, void *ptr
0da0: 29 20 7b 0a 20 20 20 20 54 63 6c 5f 43 68 61 6e  ) {.    Tcl_Chan
0db0: 6e 65 6c 20 63 68 61 6e 3b 0a 20 20 20 20 6c 6f  nel chan;.    lo
0dc0: 6e 67 20 72 65 74 20 3d 20 31 3b 0a 0a 20 20 20  ng ret = 1;..   
0dd0: 20 63 68 61 6e 20 3d 20 54 6c 73 5f 47 65 74 50   chan = Tls_GetP
0de0: 61 72 65 6e 74 28 28 53 74 61 74 65 20 2a 29 20  arent((State *) 
0df0: 42 49 4f 5f 67 65 74 5f 64 61 74 61 28 62 69 6f  BIO_get_data(bio
0e00: 29 2c 20 30 29 3b 0a 0a 20 20 20 20 64 70 72 69  ), 0);..    dpri
0e10: 6e 74 66 28 22 42 69 6f 43 74 72 6c 28 25 70 2c  ntf("BioCtrl(%p,
0e20: 20 30 78 25 78 2c 20 30 78 25 6c 78 2c 20 25 70   0x%x, 0x%lx, %p
0e30: 29 22 2c 20 62 69 6f 2c 20 63 6d 64 2c 20 6e 75  )", bio, cmd, nu
0e40: 6d 2c 20 70 74 72 29 3b 0a 0a 20 20 20 20 73 77  m, ptr);..    sw
0e50: 69 74 63 68 20 28 63 6d 64 29 20 7b 0a 09 63 61  itch (cmd) {..ca
0e60: 73 65 20 42 49 4f 5f 43 54 52 4c 5f 52 45 53 45  se BIO_CTRL_RESE
0e70: 54 3a 0a 09 09 64 70 72 69 6e 74 66 28 22 47 6f  T:...dprintf("Go
0e80: 74 20 42 49 4f 5f 43 54 52 4c 5f 52 45 53 45 54  t BIO_CTRL_RESET
0e90: 22 29 3b 0a 09 09 72 65 74 20 3d 20 30 3b 0a 09  ");...ret = 0;..
0ea0: 09 62 72 65 61 6b 3b 0a 09 63 61 73 65 20 42 49  .break;..case BI
0eb0: 4f 5f 43 5f 46 49 4c 45 5f 53 45 45 4b 3a 0a 09  O_C_FILE_SEEK:..
0ec0: 09 64 70 72 69 6e 74 66 28 22 47 6f 74 20 42 49  .dprintf("Got BI
0ed0: 4f 5f 43 5f 46 49 4c 45 5f 53 45 45 4b 22 29 3b  O_C_FILE_SEEK");
0ee0: 0a 09 09 72 65 74 20 3d 20 30 3b 0a 09 09 62 72  ...ret = 0;...br
0ef0: 65 61 6b 3b 0a 09 63 61 73 65 20 42 49 4f 5f 43  eak;..case BIO_C
0f00: 5f 46 49 4c 45 5f 54 45 4c 4c 3a 0a 09 09 64 70  _FILE_TELL:...dp
0f10: 72 69 6e 74 66 28 22 47 6f 74 20 42 49 4f 5f 43  rintf("Got BIO_C
0f20: 5f 46 49 4c 45 5f 54 45 4c 4c 22 29 3b 0a 09 09  _FILE_TELL");...
0f30: 72 65 74 20 3d 20 30 3b 0a 09 09 62 72 65 61 6b  ret = 0;...break
0f40: 3b 0a 09 63 61 73 65 20 42 49 4f 5f 43 54 52 4c  ;..case BIO_CTRL
0f50: 5f 49 4e 46 4f 3a 0a 09 09 64 70 72 69 6e 74 66  _INFO:...dprintf
0f60: 28 22 47 6f 74 20 42 49 4f 5f 43 54 52 4c 5f 49  ("Got BIO_CTRL_I
0f70: 4e 46 4f 22 29 3b 0a 09 09 72 65 74 20 3d 20 31  NFO");...ret = 1
0f80: 3b 0a 09 09 62 72 65 61 6b 3b 0a 09 63 61 73 65  ;...break;..case
0f90: 20 42 49 4f 5f 43 5f 53 45 54 5f 46 44 3a 0a 09   BIO_C_SET_FD:..
0fa0: 09 64 70 72 69 6e 74 66 28 22 55 6e 73 75 70 70  .dprintf("Unsupp
0fb0: 6f 72 74 65 64 20 63 61 6c 6c 3a 20 42 49 4f 5f  orted call: BIO_
0fc0: 43 5f 53 45 54 5f 46 44 22 29 3b 0a 09 09 72 65  C_SET_FD");...re
0fd0: 74 20 3d 20 2d 31 3b 0a 09 09 62 72 65 61 6b 3b  t = -1;...break;
0fe0: 0a 09 63 61 73 65 20 42 49 4f 5f 43 5f 47 45 54  ..case BIO_C_GET
0ff0: 5f 46 44 3a 0a 09 09 64 70 72 69 6e 74 66 28 22  _FD:...dprintf("
1000: 55 6e 73 75 70 70 6f 72 74 65 64 20 63 61 6c 6c  Unsupported call
1010: 3a 20 42 49 4f 5f 43 5f 47 45 54 5f 46 44 22 29  : BIO_C_GET_FD")
1020: 3b 0a 09 09 72 65 74 20 3d 20 2d 31 3b 0a 09 09  ;...ret = -1;...
1030: 62 72 65 61 6b 3b 0a 09 63 61 73 65 20 42 49 4f  break;..case BIO
1040: 5f 43 54 52 4c 5f 47 45 54 5f 43 4c 4f 53 45 3a  _CTRL_GET_CLOSE:
1050: 0a 09 09 64 70 72 69 6e 74 66 28 22 47 6f 74 20  ...dprintf("Got 
1060: 42 49 4f 5f 43 54 52 4c 5f 43 4c 4f 53 45 22 29  BIO_CTRL_CLOSE")
1070: 3b 0a 09 09 72 65 74 20 3d 20 42 49 4f 5f 67 65  ;...ret = BIO_ge
1080: 74 5f 73 68 75 74 64 6f 77 6e 28 62 69 6f 29 3b  t_shutdown(bio);
1090: 0a 09 09 62 72 65 61 6b 3b 0a 09 63 61 73 65 20  ...break;..case 
10a0: 42 49 4f 5f 43 54 52 4c 5f 53 45 54 5f 43 4c 4f  BIO_CTRL_SET_CLO
10b0: 53 45 3a 0a 09 09 64 70 72 69 6e 74 66 28 22 47  SE:...dprintf("G
10c0: 6f 74 20 42 49 4f 5f 53 45 54 5f 43 4c 4f 53 45  ot BIO_SET_CLOSE
10d0: 22 29 3b 0a 09 09 42 49 4f 5f 73 65 74 5f 73 68  ");...BIO_set_sh
10e0: 75 74 64 6f 77 6e 28 62 69 6f 2c 20 6e 75 6d 29  utdown(bio, num)
10f0: 3b 0a 09 09 62 72 65 61 6b 3b 0a 09 63 61 73 65  ;...break;..case
1100: 20 42 49 4f 5f 43 54 52 4c 5f 45 4f 46 3a 0a 09   BIO_CTRL_EOF:..
1110: 09 64 70 72 69 6e 74 66 28 22 47 6f 74 20 42 49  .dprintf("Got BI
1120: 4f 5f 43 54 52 4c 5f 45 4f 46 22 29 3b 0a 09 09  O_CTRL_EOF");...
1130: 72 65 74 20 3d 20 28 28 63 68 61 6e 29 20 3f 20  ret = ((chan) ? 
1140: 54 63 6c 5f 45 6f 66 28 63 68 61 6e 29 20 3a 20  Tcl_Eof(chan) : 
1150: 31 29 3b 0a 09 09 62 72 65 61 6b 3b 0a 09 63 61  1);...break;..ca
1160: 73 65 20 42 49 4f 5f 43 54 52 4c 5f 50 45 4e 44  se BIO_CTRL_PEND
1170: 49 4e 47 3a 0a 09 09 64 70 72 69 6e 74 66 28 22  ING:...dprintf("
1180: 47 6f 74 20 42 49 4f 5f 43 54 52 4c 5f 50 45 4e  Got BIO_CTRL_PEN
1190: 44 49 4e 47 22 29 3b 0a 09 09 72 65 74 20 3d 20  DING");...ret = 
11a0: 28 28 63 68 61 6e 29 20 3f 20 28 28 54 63 6c 5f  ((chan) ? ((Tcl_
11b0: 49 6e 70 75 74 42 75 66 66 65 72 65 64 28 63 68  InputBuffered(ch
11c0: 61 6e 29 20 3f 20 31 20 3a 20 30 29 29 20 3a 20  an) ? 1 : 0)) : 
11d0: 30 29 3b 0a 09 09 64 70 72 69 6e 74 66 28 22 42  0);...dprintf("B
11e0: 49 4f 5f 43 54 52 4c 5f 50 45 4e 44 49 4e 47 28  IO_CTRL_PENDING(
11f0: 25 64 29 22 2c 20 28 69 6e 74 29 20 72 65 74 29  %d)", (int) ret)
1200: 3b 0a 09 09 62 72 65 61 6b 3b 0a 09 63 61 73 65  ;...break;..case
1210: 20 42 49 4f 5f 43 54 52 4c 5f 57 50 45 4e 44 49   BIO_CTRL_WPENDI
1220: 4e 47 3a 0a 09 09 64 70 72 69 6e 74 66 28 22 47  NG:...dprintf("G
1230: 6f 74 20 42 49 4f 5f 43 54 52 4c 5f 57 50 45 4e  ot BIO_CTRL_WPEN
1240: 44 49 4e 47 22 29 3b 0a 09 09 72 65 74 20 3d 20  DING");...ret = 
1250: 30 3b 0a 09 09 62 72 65 61 6b 3b 0a 09 63 61 73  0;...break;..cas
1260: 65 20 42 49 4f 5f 43 54 52 4c 5f 44 55 50 3a 0a  e BIO_CTRL_DUP:.
1270: 09 09 64 70 72 69 6e 74 66 28 22 47 6f 74 20 42  ..dprintf("Got B
1280: 49 4f 5f 43 54 52 4c 5f 44 55 50 22 29 3b 0a 09  IO_CTRL_DUP");..
1290: 09 62 72 65 61 6b 3b 0a 09 63 61 73 65 20 42 49  .break;..case BI
12a0: 4f 5f 43 54 52 4c 5f 46 4c 55 53 48 3a 0a 09 09  O_CTRL_FLUSH:...
12b0: 64 70 72 69 6e 74 66 28 22 47 6f 74 20 42 49 4f  dprintf("Got BIO
12c0: 5f 43 54 52 4c 5f 46 4c 55 53 48 22 29 3b 0a 09  _CTRL_FLUSH");..
12d0: 09 72 65 74 20 3d 20 28 28 63 68 61 6e 29 20 26  .ret = ((chan) &
12e0: 26 20 28 54 63 6c 5f 57 72 69 74 65 52 61 77 28  & (Tcl_WriteRaw(
12f0: 63 68 61 6e 2c 20 22 22 2c 20 30 29 20 3e 3d 20  chan, "", 0) >= 
1300: 30 29 20 3f 20 31 20 3a 20 2d 31 29 3b 0a 09 09  0) ? 1 : -1);...
1310: 64 70 72 69 6e 74 66 28 22 42 49 4f 5f 43 54 52  dprintf("BIO_CTR
1320: 4c 5f 46 4c 55 53 48 20 72 65 74 75 72 6e 69 6e  L_FLUSH returnin
1330: 67 20 76 61 6c 75 65 20 25 6c 69 22 2c 20 72 65  g value %li", re
1340: 74 29 3b 0a 09 09 62 72 65 61 6b 3b 0a 09 63 61  t);...break;..ca
1350: 73 65 20 42 49 4f 5f 43 54 52 4c 5f 50 55 53 48  se BIO_CTRL_PUSH
1360: 3a 0a 09 09 64 70 72 69 6e 74 66 28 22 47 6f 74  :...dprintf("Got
1370: 20 42 49 4f 5f 43 54 52 4c 5f 50 55 53 48 22 29   BIO_CTRL_PUSH")
1380: 3b 0a 09 09 72 65 74 20 3d 20 30 3b 0a 09 09 62  ;...ret = 0;...b
1390: 72 65 61 6b 3b 0a 09 63 61 73 65 20 42 49 4f 5f  reak;..case BIO_
13a0: 43 54 52 4c 5f 50 4f 50 3a 0a 09 09 64 70 72 69  CTRL_POP:...dpri
13b0: 6e 74 66 28 22 47 6f 74 20 42 49 4f 5f 43 54 52  ntf("Got BIO_CTR
13c0: 4c 5f 50 4f 50 22 29 3b 0a 09 09 72 65 74 20 3d  L_POP");...ret =
13d0: 20 30 3b 0a 09 09 62 72 65 61 6b 3b 0a 09 63 61   0;...break;..ca
13e0: 73 65 20 42 49 4f 5f 43 54 52 4c 5f 53 45 54 3a  se BIO_CTRL_SET:
13f0: 0a 09 09 64 70 72 69 6e 74 66 28 22 47 6f 74 20  ...dprintf("Got 
1400: 42 49 4f 5f 43 54 52 4c 5f 53 45 54 22 29 3b 0a  BIO_CTRL_SET");.
1410: 09 09 72 65 74 20 3d 20 30 3b 0a 09 09 62 72 65  ..ret = 0;...bre
1420: 61 6b 3b 0a 09 63 61 73 65 20 42 49 4f 5f 43 54  ak;..case BIO_CT
1430: 52 4c 5f 47 45 54 20 3a 0a 09 09 64 70 72 69 6e  RL_GET :...dprin
1440: 74 66 28 22 47 6f 74 20 42 49 4f 5f 43 54 52 4c  tf("Got BIO_CTRL
1450: 5f 47 45 54 20 22 29 3b 0a 09 09 72 65 74 20 3d  _GET ");...ret =
1460: 20 30 3b 0a 09 09 62 72 65 61 6b 3b 0a 23 69 66   0;...break;.#if
1470: 64 65 66 20 42 49 4f 5f 43 54 52 4c 5f 47 45 54  def BIO_CTRL_GET
1480: 5f 4b 54 4c 53 5f 53 45 4e 44 0a 09 63 61 73 65  _KTLS_SEND..case
1490: 20 42 49 4f 5f 43 54 52 4c 5f 47 45 54 5f 4b 54   BIO_CTRL_GET_KT
14a0: 4c 53 5f 53 45 4e 44 3a 0a 09 09 64 70 72 69 6e  LS_SEND:...dprin
14b0: 74 66 28 22 47 6f 74 20 42 49 4f 5f 43 54 52 4c  tf("Got BIO_CTRL
14c0: 5f 47 45 54 5f 4b 54 4c 53 5f 53 45 4e 44 22 29  _GET_KTLS_SEND")
14d0: 3b 0a 09 09 72 65 74 20 3d 20 30 3b 0a 09 09 62  ;...ret = 0;...b
14e0: 72 65 61 6b 3b 0a 23 65 6e 64 69 66 0a 23 69 66  reak;.#endif.#if
14f0: 64 65 66 20 42 49 4f 5f 43 54 52 4c 5f 47 45 54  def BIO_CTRL_GET
1500: 5f 4b 54 4c 53 5f 52 45 43 56 0a 09 63 61 73 65  _KTLS_RECV..case
1510: 20 42 49 4f 5f 43 54 52 4c 5f 47 45 54 5f 4b 54   BIO_CTRL_GET_KT
1520: 4c 53 5f 52 45 43 56 3a 0a 09 09 64 70 72 69 6e  LS_RECV:...dprin
1530: 74 66 28 22 47 6f 74 20 42 49 4f 5f 43 54 52 4c  tf("Got BIO_CTRL
1540: 5f 47 45 54 5f 4b 54 4c 53 5f 52 45 43 56 22 29  _GET_KTLS_RECV")
1550: 3b 0a 09 09 72 65 74 20 3d 20 30 3b 0a 09 09 62  ;...ret = 0;...b
1560: 72 65 61 6b 3b 0a 23 65 6e 64 69 66 0a 09 64 65  reak;.#endif..de
1570: 66 61 75 6c 74 3a 0a 09 09 64 70 72 69 6e 74 66  fault:...dprintf
1580: 28 22 47 6f 74 20 75 6e 6b 6e 6f 77 6e 20 63 6f  ("Got unknown co
1590: 6e 74 72 6f 6c 20 63 6f 6d 6d 61 6e 64 20 28 25  ntrol command (%
15a0: 69 29 22 2c 20 63 6d 64 29 3b 0a 09 09 72 65 74  i)", cmd);...ret
15b0: 20 3d 20 2d 32 3b 0a 09 09 62 72 65 61 6b 3b 0a   = -2;...break;.
15c0: 20 20 20 20 7d 0a 20 20 20 20 72 65 74 75 72 6e      }.    return
15d0: 20 72 65 74 3b 0a 7d 0a 0a 73 74 61 74 69 63 20   ret;.}..static 
15e0: 69 6e 74 20 42 69 6f 4e 65 77 28 42 49 4f 20 2a  int BioNew(BIO *
15f0: 62 69 6f 29 20 7b 0a 20 20 20 20 64 70 72 69 6e  bio) {.    dprin
1600: 74 66 28 22 42 69 6f 4e 65 77 28 25 70 29 20 63  tf("BioNew(%p) c
1610: 61 6c 6c 65 64 22 2c 20 62 69 6f 29 3b 0a 0a 20  alled", bio);.. 
1620: 20 20 20 42 49 4f 5f 73 65 74 5f 69 6e 69 74 28     BIO_set_init(
1630: 62 69 6f 2c 20 30 29 3b 0a 20 20 20 20 42 49 4f  bio, 0);.    BIO
1640: 5f 73 65 74 5f 64 61 74 61 28 62 69 6f 2c 20 4e  _set_data(bio, N
1650: 55 4c 4c 29 3b 0a 20 20 20 20 42 49 4f 5f 63 6c  ULL);.    BIO_cl
1660: 65 61 72 5f 66 6c 61 67 73 28 62 69 6f 2c 20 2d  ear_flags(bio, -
1670: 31 29 3b 0a 20 20 20 20 72 65 74 75 72 6e 20 31  1);.    return 1
1680: 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 20  ;.}..static int 
1690: 42 69 6f 46 72 65 65 28 42 49 4f 20 2a 62 69 6f  BioFree(BIO *bio
16a0: 29 20 7b 0a 20 20 20 20 69 66 20 28 62 69 6f 20  ) {.    if (bio 
16b0: 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 75  == NULL) {..retu
16c0: 72 6e 28 30 29 3b 0a 20 20 20 20 7d 0a 0a 20 20  rn(0);.    }..  
16d0: 20 20 64 70 72 69 6e 74 66 28 22 42 69 6f 46 72    dprintf("BioFr
16e0: 65 65 28 25 70 29 20 63 61 6c 6c 65 64 22 2c 20  ee(%p) called", 
16f0: 62 69 6f 29 3b 0a 0a 20 20 20 20 69 66 20 28 42  bio);..    if (B
1700: 49 4f 5f 67 65 74 5f 73 68 75 74 64 6f 77 6e 28  IO_get_shutdown(
1710: 62 69 6f 29 29 20 7b 0a 09 69 66 20 28 42 49 4f  bio)) {..if (BIO
1720: 5f 67 65 74 5f 69 6e 69 74 28 62 69 6f 29 29 20  _get_init(bio)) 
1730: 7b 0a 09 20 20 20 20 2f 2a 73 68 75 74 64 6f 77  {..    /*shutdow
1740: 6e 28 62 69 6f 2d 3e 6e 75 6d 2c 20 32 29 20 2a  n(bio->num, 2) *
1750: 2f 0a 09 20 20 20 20 2f 2a 63 6c 6f 73 65 73 6f  /..    /*closeso
1760: 63 6b 65 74 28 62 69 6f 2d 3e 6e 75 6d 29 20 2a  cket(bio->num) *
1770: 2f 0a 09 7d 0a 0a 09 42 49 4f 5f 73 65 74 5f 69  /..}...BIO_set_i
1780: 6e 69 74 28 62 69 6f 2c 20 30 29 3b 0a 09 42 49  nit(bio, 0);..BI
1790: 4f 5f 63 6c 65 61 72 5f 66 6c 61 67 73 28 62 69  O_clear_flags(bi
17a0: 6f 2c 20 2d 31 29 3b 0a 20 20 20 20 7d 0a 20 20  o, -1);.    }.  
17b0: 20 20 72 65 74 75 72 6e 20 31 3b 0a 7d 0a 0a 42    return 1;.}..B
17c0: 49 4f 20 2a 42 49 4f 5f 6e 65 77 5f 74 63 6c 28  IO *BIO_new_tcl(
17d0: 53 74 61 74 65 20 2a 73 74 61 74 65 50 74 72 2c  State *statePtr,
17e0: 20 69 6e 74 20 66 6c 61 67 73 29 20 7b 0a 20 20   int flags) {.  
17f0: 20 20 42 49 4f 20 2a 62 69 6f 3b 0a 20 20 20 20    BIO *bio;.    
1800: 73 74 61 74 69 63 20 42 49 4f 5f 4d 45 54 48 4f  static BIO_METHO
1810: 44 20 2a 42 69 6f 4d 65 74 68 6f 64 73 20 3d 20  D *BioMethods = 
1820: 4e 55 4c 4c 3b 0a 23 69 66 64 65 66 20 54 43 4c  NULL;.#ifdef TCL
1830: 54 4c 53 5f 53 53 4c 5f 55 53 45 5f 46 41 53 54  TLS_SSL_USE_FAST
1840: 50 41 54 48 0a 20 20 20 20 54 63 6c 5f 43 68 61  PATH.    Tcl_Cha
1850: 6e 6e 65 6c 20 70 61 72 65 6e 74 43 68 61 6e 6e  nnel parentChann
1860: 65 6c 3b 0a 20 20 20 20 63 6f 6e 73 74 20 54 63  el;.    const Tc
1870: 6c 5f 43 68 61 6e 6e 65 6c 54 79 70 65 20 2a 70  l_ChannelType *p
1880: 61 72 65 6e 74 43 68 61 6e 6e 65 6c 54 79 70 65  arentChannelType
1890: 3b 0a 20 20 20 20 76 6f 69 64 20 2a 70 61 72 65  ;.    void *pare
18a0: 6e 74 43 68 61 6e 6e 65 6c 46 64 49 6e 5f 70 2c  ntChannelFdIn_p,
18b0: 20 2a 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c 46   *parentChannelF
18c0: 64 4f 75 74 5f 70 3b 0a 20 20 20 20 69 6e 74 20  dOut_p;.    int 
18d0: 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c 46 64 49  parentChannelFdI
18e0: 6e 2c 20 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c  n, parentChannel
18f0: 46 64 4f 75 74 2c 20 70 61 72 65 6e 74 43 68 61  FdOut, parentCha
1900: 6e 6e 65 6c 46 64 3b 0a 20 20 20 20 69 6e 74 20  nnelFd;.    int 
1910: 76 61 6c 69 64 50 61 72 65 6e 74 43 68 61 6e 6e  validParentChann
1920: 65 6c 46 64 3b 0a 20 20 20 20 69 6e 74 20 74 63  elFd;.    int tc
1930: 6c 47 65 74 43 68 61 6e 6e 65 6c 48 61 6e 64 6c  lGetChannelHandl
1940: 65 52 65 74 3b 0a 23 65 6e 64 69 66 0a 0a 20 20  eRet;.#endif..  
1950: 20 20 64 70 72 69 6e 74 66 28 22 42 49 4f 5f 6e    dprintf("BIO_n
1960: 65 77 5f 74 63 6c 28 29 20 63 61 6c 6c 65 64 22  ew_tcl() called"
1970: 29 3b 0a 0a 20 20 20 20 69 66 20 28 42 69 6f 4d  );..    if (BioM
1980: 65 74 68 6f 64 73 20 3d 3d 20 4e 55 4c 4c 29 20  ethods == NULL) 
1990: 7b 0a 09 42 69 6f 4d 65 74 68 6f 64 73 20 3d 20  {..BioMethods = 
19a0: 42 49 4f 5f 6d 65 74 68 5f 6e 65 77 28 42 49 4f  BIO_meth_new(BIO
19b0: 5f 54 59 50 45 5f 54 43 4c 2c 20 22 74 63 6c 22  _TYPE_TCL, "tcl"
19c0: 29 3b 0a 09 42 49 4f 5f 6d 65 74 68 5f 73 65 74  );..BIO_meth_set
19d0: 5f 77 72 69 74 65 28 42 69 6f 4d 65 74 68 6f 64  _write(BioMethod
19e0: 73 2c 20 42 69 6f 57 72 69 74 65 29 3b 0a 09 42  s, BioWrite);..B
19f0: 49 4f 5f 6d 65 74 68 5f 73 65 74 5f 72 65 61 64  IO_meth_set_read
1a00: 28 42 69 6f 4d 65 74 68 6f 64 73 2c 20 42 69 6f  (BioMethods, Bio
1a10: 52 65 61 64 29 3b 0a 09 42 49 4f 5f 6d 65 74 68  Read);..BIO_meth
1a20: 5f 73 65 74 5f 70 75 74 73 28 42 69 6f 4d 65 74  _set_puts(BioMet
1a30: 68 6f 64 73 2c 20 42 69 6f 50 75 74 73 29 3b 0a  hods, BioPuts);.
1a40: 09 42 49 4f 5f 6d 65 74 68 5f 73 65 74 5f 63 74  .BIO_meth_set_ct
1a50: 72 6c 28 42 69 6f 4d 65 74 68 6f 64 73 2c 20 42  rl(BioMethods, B
1a60: 69 6f 43 74 72 6c 29 3b 0a 09 42 49 4f 5f 6d 65  ioCtrl);..BIO_me
1a70: 74 68 5f 73 65 74 5f 63 72 65 61 74 65 28 42 69  th_set_create(Bi
1a80: 6f 4d 65 74 68 6f 64 73 2c 20 42 69 6f 4e 65 77  oMethods, BioNew
1a90: 29 3b 0a 09 42 49 4f 5f 6d 65 74 68 5f 73 65 74  );..BIO_meth_set
1aa0: 5f 64 65 73 74 72 6f 79 28 42 69 6f 4d 65 74 68  _destroy(BioMeth
1ab0: 6f 64 73 2c 20 42 69 6f 46 72 65 65 29 3b 0a 20  ods, BioFree);. 
1ac0: 20 20 20 7d 0a 0a 20 20 20 20 69 66 20 28 73 74     }..    if (st
1ad0: 61 74 65 50 74 72 20 3d 3d 20 4e 55 4c 4c 29 20  atePtr == NULL) 
1ae0: 7b 0a 09 64 70 72 69 6e 74 66 28 22 41 73 6b 65  {..dprintf("Aske
1af0: 64 20 74 6f 20 73 65 74 75 70 20 61 20 4e 55 4c  d to setup a NUL
1b00: 4c 20 73 74 61 74 65 2c 20 6a 75 73 74 20 63 72  L state, just cr
1b10: 65 61 74 69 6e 67 20 74 68 65 20 69 6e 69 74 69  eating the initi
1b20: 61 6c 20 63 6f 6e 66 69 67 75 72 61 74 69 6f 6e  al configuration
1b30: 22 29 3b 0a 0a 09 72 65 74 75 72 6e 28 4e 55 4c  ");...return(NUL
1b40: 4c 29 3b 0a 20 20 20 20 7d 0a 0a 23 69 66 64 65  L);.    }..#ifde
1b50: 66 20 54 43 4c 54 4c 53 5f 53 53 4c 5f 55 53 45  f TCLTLS_SSL_USE
1b60: 5f 46 41 53 54 50 41 54 48 0a 20 20 20 20 2f 2a  _FASTPATH.    /*
1b70: 0a 20 20 20 20 20 2a 20 49 66 20 74 68 65 20 63  .     * If the c
1b80: 68 61 6e 6e 65 6c 20 63 61 6e 20 62 65 20 6d 61  hannel can be ma
1b90: 70 70 65 64 20 62 61 63 6b 20 74 6f 20 61 20 66  pped back to a f
1ba0: 69 6c 65 20 64 65 73 63 72 69 70 74 6f 72 2c 20  ile descriptor, 
1bb0: 6a 75 73 74 20 75 73 65 20 74 68 65 20 66 69 6c  just use the fil
1bc0: 65 20 64 65 73 63 72 69 70 74 6f 72 0a 20 20 20  e descriptor.   
1bd0: 20 20 2a 20 77 69 74 68 20 74 68 65 20 53 53 4c    * with the SSL
1be0: 20 6c 69 62 72 61 72 79 20 73 69 6e 63 65 20 69   library since i
1bf0: 74 20 77 69 6c 6c 20 6c 69 6b 65 6c 79 20 62 65  t will likely be
1c00: 20 6f 70 74 69 6d 69 7a 65 64 20 66 6f 72 20 74   optimized for t
1c10: 68 69 73 2e 0a 20 20 20 20 20 2a 2f 0a 20 20 20  his..     */.   
1c20: 20 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c 20 3d   parentChannel =
1c30: 20 54 6c 73 5f 47 65 74 50 61 72 65 6e 74 28 73   Tls_GetParent(s
1c40: 74 61 74 65 50 74 72 2c 20 30 29 3b 0a 20 20 20  tatePtr, 0);.   
1c50: 20 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c 54 79   parentChannelTy
1c60: 70 65 20 3d 20 54 63 6c 5f 47 65 74 43 68 61 6e  pe = Tcl_GetChan
1c70: 6e 65 6c 54 79 70 65 28 70 61 72 65 6e 74 43 68  nelType(parentCh
1c80: 61 6e 6e 65 6c 29 3b 0a 0a 20 20 20 20 76 61 6c  annel);..    val
1c90: 69 64 50 61 72 65 6e 74 43 68 61 6e 6e 65 6c 46  idParentChannelF
1ca0: 64 20 3d 20 30 3b 0a 20 20 20 20 69 66 20 28 73  d = 0;.    if (s
1cb0: 74 72 63 6d 70 28 70 61 72 65 6e 74 43 68 61 6e  trcmp(parentChan
1cc0: 6e 65 6c 54 79 70 65 2d 3e 74 79 70 65 4e 61 6d  nelType->typeNam
1cd0: 65 2c 20 22 74 63 70 22 29 20 3d 3d 20 30 29 20  e, "tcp") == 0) 
1ce0: 7b 0a 09 74 63 6c 47 65 74 43 68 61 6e 6e 65 6c  {..tclGetChannel
1cf0: 48 61 6e 64 6c 65 52 65 74 20 3d 20 54 63 6c 5f  HandleRet = Tcl_
1d00: 47 65 74 43 68 61 6e 6e 65 6c 48 61 6e 64 6c 65  GetChannelHandle
1d10: 28 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c 2c 20  (parentChannel, 
1d20: 54 43 4c 5f 52 45 41 44 41 42 4c 45 2c 20 28 43  TCL_READABLE, (C
1d30: 6c 69 65 6e 74 44 61 74 61 29 20 26 70 61 72 65  lientData) &pare
1d40: 6e 74 43 68 61 6e 6e 65 6c 46 64 49 6e 5f 70 29  ntChannelFdIn_p)
1d50: 3b 0a 09 69 66 20 28 74 63 6c 47 65 74 43 68 61  ;..if (tclGetCha
1d60: 6e 6e 65 6c 48 61 6e 64 6c 65 52 65 74 20 3d 3d  nnelHandleRet ==
1d70: 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 20 20 20 20   TCL_OK) {..    
1d80: 74 63 6c 47 65 74 43 68 61 6e 6e 65 6c 48 61 6e  tclGetChannelHan
1d90: 64 6c 65 52 65 74 20 3d 20 54 63 6c 5f 47 65 74  dleRet = Tcl_Get
1da0: 43 68 61 6e 6e 65 6c 48 61 6e 64 6c 65 28 70 61  ChannelHandle(pa
1db0: 72 65 6e 74 43 68 61 6e 6e 65 6c 2c 20 54 43 4c  rentChannel, TCL
1dc0: 5f 57 52 49 54 41 42 4c 45 2c 20 28 43 6c 69 65  _WRITABLE, (Clie
1dd0: 6e 74 44 61 74 61 29 20 26 70 61 72 65 6e 74 43  ntData) &parentC
1de0: 68 61 6e 6e 65 6c 46 64 4f 75 74 5f 70 29 3b 0a  hannelFdOut_p);.
1df0: 09 20 20 20 20 69 66 20 28 74 63 6c 47 65 74 43  .    if (tclGetC
1e00: 68 61 6e 6e 65 6c 48 61 6e 64 6c 65 52 65 74 20  hannelHandleRet 
1e10: 3d 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 09 70  == TCL_OK) {...p
1e20: 61 72 65 6e 74 43 68 61 6e 6e 65 6c 46 64 49 6e  arentChannelFdIn
1e30: 20 3d 20 50 54 52 32 49 4e 54 28 70 61 72 65 6e   = PTR2INT(paren
1e40: 74 43 68 61 6e 6e 65 6c 46 64 49 6e 5f 70 29 3b  tChannelFdIn_p);
1e50: 0a 09 09 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c  ...parentChannel
1e60: 46 64 4f 75 74 20 3d 20 50 54 52 32 49 4e 54 28  FdOut = PTR2INT(
1e70: 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c 46 64 4f  parentChannelFdO
1e80: 75 74 5f 70 29 3b 0a 09 09 69 66 20 28 70 61 72  ut_p);...if (par
1e90: 65 6e 74 43 68 61 6e 6e 65 6c 46 64 49 6e 20 3d  entChannelFdIn =
1ea0: 3d 20 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c 46  = parentChannelF
1eb0: 64 4f 75 74 29 20 7b 0a 09 09 20 20 20 20 70 61  dOut) {...    pa
1ec0: 72 65 6e 74 43 68 61 6e 6e 65 6c 46 64 20 3d 20  rentChannelFd = 
1ed0: 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c 46 64 49  parentChannelFdI
1ee0: 6e 3b 0a 09 09 20 20 20 20 76 61 6c 69 64 50 61  n;...    validPa
1ef0: 72 65 6e 74 43 68 61 6e 6e 65 6c 46 64 20 3d 20  rentChannelFd = 
1f00: 31 3b 0a 09 09 7d 0a 09 20 20 20 20 7d 0a 09 7d  1;...}..    }..}
1f10: 0a 20 20 20 20 7d 0a 0a 20 20 20 20 69 66 20 28  .    }..    if (
1f20: 76 61 6c 69 64 50 61 72 65 6e 74 43 68 61 6e 6e  validParentChann
1f30: 65 6c 46 64 29 20 7b 0a 09 64 70 72 69 6e 74 66  elFd) {..dprintf
1f40: 28 22 57 65 20 66 6f 75 6e 64 20 61 20 73 68 6f  ("We found a sho
1f50: 72 74 63 75 74 2c 20 74 68 69 73 20 63 68 61 6e  rtcut, this chan
1f60: 6e 65 6c 20 69 73 20 62 61 63 6b 65 64 20 62 79  nel is backed by
1f70: 20 61 20 73 6f 63 6b 65 74 3a 20 25 69 22 2c 20   a socket: %i", 
1f80: 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c 46 64 49  parentChannelFdI
1f90: 6e 29 3b 0a 09 62 69 6f 20 3d 20 42 49 4f 5f 6e  n);..bio = BIO_n
1fa0: 65 77 5f 73 6f 63 6b 65 74 28 70 61 72 65 6e 74  ew_socket(parent
1fb0: 43 68 61 6e 6e 65 6c 46 64 2c 20 66 6c 61 67 73  ChannelFd, flags
1fc0: 29 3b 0a 09 73 74 61 74 65 50 74 72 2d 3e 66 6c  );..statePtr->fl
1fd0: 61 67 73 20 7c 3d 20 54 4c 53 5f 54 43 4c 5f 46  ags |= TLS_TCL_F
1fe0: 41 53 54 50 41 54 48 3b 0a 09 72 65 74 75 72 6e  ASTPATH;..return
1ff0: 28 62 69 6f 29 3b 0a 20 20 20 20 7d 0a 0a 20 20  (bio);.    }..  
2000: 20 20 64 70 72 69 6e 74 66 28 22 46 61 6c 6c 69    dprintf("Falli
2010: 6e 67 20 62 61 63 6b 20 74 6f 20 54 63 6c 20 49  ng back to Tcl I
2020: 2f 4f 20 66 6f 72 20 74 68 69 73 20 63 68 61 6e  /O for this chan
2030: 6e 65 6c 22 29 3b 0a 23 65 6e 64 69 66 0a 0a 20  nel");.#endif.. 
2040: 20 20 20 62 69 6f 20 3d 20 42 49 4f 5f 6e 65 77     bio = BIO_new
2050: 28 42 69 6f 4d 65 74 68 6f 64 73 29 3b 0a 20 20  (BioMethods);.  
2060: 20 20 42 49 4f 5f 73 65 74 5f 64 61 74 61 28 62    BIO_set_data(b
2070: 69 6f 2c 20 73 74 61 74 65 50 74 72 29 3b 0a 20  io, statePtr);. 
2080: 20 20 20 42 49 4f 5f 73 65 74 5f 73 68 75 74 64     BIO_set_shutd
2090: 6f 77 6e 28 62 69 6f 2c 20 66 6c 61 67 73 29 3b  own(bio, flags);
20a0: 0a 20 20 20 20 42 49 4f 5f 73 65 74 5f 69 6e 69  .    BIO_set_ini
20b0: 74 28 62 69 6f 2c 20 31 29 3b 0a 20 20 20 20 72  t(bio, 1);.    r
20c0: 65 74 75 72 6e 28 62 69 6f 29 3b 0a 7d 0a        eturn(bio);.}.