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 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 20 62 75 66 4c 65 6e 29 3b 0a _Size) bufLen);.
07e0: 0a 20 20 20 20 74 63 6c 45 6f 66 43 68 61 6e 20 . tclEofChan
07f0: 3d 20 54 63 6c 5f 45 6f 66 28 63 68 61 6e 29 3b = Tcl_Eof(chan);
0800: 0a 20 20 20 20 74 63 6c 45 72 72 6e 6f 20 3d 20 . tclErrno =
0810: 54 63 6c 5f 47 65 74 45 72 72 6e 6f 28 29 3b 0a Tcl_GetErrno();.
0820: 0a 20 20 20 20 64 70 72 69 6e 74 66 28 22 5b 63 . dprintf("[c
0830: 68 61 6e 3d 25 70 5d 20 42 69 6f 52 65 61 64 28 han=%p] BioRead(
0840: 25 64 29 20 2d 3e 20 25 22 20 54 43 4c 5f 53 49 %d) -> %" TCL_SI
0850: 5a 45 5f 4d 4f 44 49 46 49 45 52 20 22 64 20 5b ZE_MODIFIER "d [
0860: 74 63 6c 45 6f 66 3d 25 64 3b 20 74 63 6c 45 72 tclEof=%d; tclEr
0870: 72 6e 6f 3d 25 64 5d 22 2c 0a 09 28 76 6f 69 64 rno=%d]",..(void
0880: 20 2a 29 20 63 68 61 6e 2c 20 62 75 66 4c 65 6e *) chan, bufLen
0890: 2c 20 72 65 74 2c 20 74 63 6c 45 6f 66 43 68 61 , ret, tclEofCha
08a0: 6e 2c 20 74 63 6c 45 72 72 6e 6f 29 3b 0a 0a 20 n, tclErrno);..
08b0: 20 20 20 42 49 4f 5f 63 6c 65 61 72 5f 66 6c 61 BIO_clear_fla
08c0: 67 73 28 62 69 6f 2c 20 42 49 4f 5f 46 4c 41 47 gs(bio, BIO_FLAG
08d0: 53 5f 52 45 41 44 20 7c 20 42 49 4f 5f 46 4c 41 S_READ | BIO_FLA
08e0: 47 53 5f 53 48 4f 55 4c 44 5f 52 45 54 52 59 29 GS_SHOULD_RETRY)
08f0: 3b 0a 0a 20 20 20 20 69 66 20 28 74 63 6c 45 6f ;.. if (tclEo
0900: 66 43 68 61 6e 20 26 26 20 72 65 74 20 3c 3d 20 fChan && ret <=
0910: 30 29 20 7b 0a 09 64 70 72 69 6e 74 66 28 22 47 0) {..dprintf("G
0920: 6f 74 20 45 4f 46 20 77 68 69 6c 65 20 72 65 61 ot EOF while rea
0930: 64 69 6e 67 2c 20 72 65 74 75 72 6e 69 6e 67 20 ding, returning
0940: 61 20 43 6f 6e 6e 65 63 74 69 6f 6e 20 52 65 73 a Connection Res
0950: 65 74 20 65 72 72 6f 72 20 77 68 69 63 68 20 6d et error which m
0960: 61 70 73 20 74 6f 20 53 6f 66 74 20 45 4f 46 22 aps to Soft EOF"
0970: 29 3b 0a 09 54 63 6c 5f 53 65 74 45 72 72 6e 6f );..Tcl_SetErrno
0980: 28 45 43 4f 4e 4e 52 45 53 45 54 29 3b 0a 09 72 (ECONNRESET);..r
0990: 65 74 20 3d 20 30 3b 0a 0a 20 20 20 20 7d 20 65 et = 0;.. } e
09a0: 6c 73 65 20 69 66 20 28 72 65 74 20 3d 3d 20 30 lse if (ret == 0
09b0: 29 20 7b 0a 09 64 70 72 69 6e 74 66 28 22 47 6f ) {..dprintf("Go
09c0: 74 20 30 20 66 72 6f 6d 20 54 63 6c 5f 52 65 61 t 0 from Tcl_Rea
09d0: 64 20 6f 72 20 54 63 6c 5f 52 65 61 64 52 61 77 d or Tcl_ReadRaw
09e0: 2c 20 61 6e 64 20 45 4f 46 20 69 73 20 6e 6f 74 , and EOF is not
09f0: 20 73 65 74 3b 20 72 65 74 20 3d 20 30 22 29 3b set; ret = 0");
0a00: 0a 09 64 70 72 69 6e 74 66 28 22 53 65 74 74 69 ..dprintf("Setti
0a10: 6e 67 20 72 65 74 72 79 20 72 65 61 64 20 66 6c ng retry read fl
0a20: 61 67 22 29 3b 0a 09 42 49 4f 5f 73 65 74 5f 72 ag");..BIO_set_r
0a30: 65 74 72 79 5f 72 65 61 64 28 62 69 6f 29 3b 0a etry_read(bio);.
0a40: 0a 20 20 20 20 7d 20 65 6c 73 65 20 69 66 20 28 . } else if (
0a50: 72 65 74 20 3c 20 30 29 20 7b 0a 09 64 70 72 69 ret < 0) {..dpri
0a60: 6e 74 66 28 22 57 65 20 67 6f 74 20 73 6f 6d 65 ntf("We got some
0a70: 20 6b 69 6e 64 20 6f 66 20 49 2f 4f 20 65 72 72 kind of I/O err
0a80: 6f 72 22 29 3b 0a 0a 09 69 66 20 28 74 63 6c 45 or");...if (tclE
0a90: 72 72 6e 6f 20 3d 3d 20 45 41 47 41 49 4e 29 20 rrno == EAGAIN)
0aa0: 7b 0a 09 20 20 20 20 64 70 72 69 6e 74 66 28 22 {.. dprintf("
0ab0: 49 74 27 73 20 45 41 47 41 49 4e 22 29 3b 0a 09 It's EAGAIN");..
0ac0: 7d 20 65 6c 73 65 20 7b 0a 09 20 20 20 20 64 70 } else {.. dp
0ad0: 72 69 6e 74 66 28 22 49 74 27 73 20 61 6e 20 75 rintf("It's an u
0ae0: 6e 65 78 70 65 63 74 65 64 20 65 72 72 6f 72 3a nexpected error:
0af0: 20 25 73 2f 25 69 22 2c 20 54 63 6c 5f 45 72 72 %s/%i", Tcl_Err
0b00: 6e 6f 4d 73 67 28 74 63 6c 45 72 72 6e 6f 29 2c noMsg(tclErrno),
0b10: 20 74 63 6c 45 72 72 6e 6f 29 3b 0a 09 7d 0a 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 20 28 76 MODIFIER "d", (v
0c80: 6f 69 64 20 2a 29 20 62 69 6f 2c 0a 09 62 75 66 oid *) bio,..buf
0c90: 4c 65 6e 2c 20 28 76 6f 69 64 20 2a 29 20 63 68 Len, (void *) ch
0ca0: 61 6e 2c 20 72 65 74 29 3b 0a 0a 20 20 20 20 72 an, ret);.. r
0cb0: 65 74 75 72 6e 28 28 69 6e 74 29 20 72 65 74 29 eturn((int) ret)
0cc0: 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 ;.}..static int
0cd0: 42 69 6f 50 75 74 73 28 42 49 4f 20 2a 62 69 6f BioPuts(BIO *bio
0ce0: 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 74 , const char *st
0cf0: 72 29 20 7b 0a 20 20 20 20 64 70 72 69 6e 74 66 r) {. dprintf
0d00: 28 22 42 69 6f 50 75 74 73 28 25 70 2c 20 3c 73 ("BioPuts(%p, <s
0d10: 74 72 69 6e 67 3a 25 70 3e 29 20 63 61 6c 6c 65 tring:%p>) calle
0d20: 64 22 2c 20 62 69 6f 2c 20 73 74 72 29 3b 0a 0a d", bio, str);..
0d30: 20 20 20 20 72 65 74 75 72 6e 28 42 69 6f 57 72 return(BioWr
0d40: 69 74 65 28 62 69 6f 2c 20 73 74 72 2c 20 28 69 ite(bio, str, (i
0d50: 6e 74 29 20 73 74 72 6c 65 6e 28 73 74 72 29 29 nt) 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 28 76 6f 69 64 20 2a 29 20 62 69 6f )", (void *) bio
0e40: 2c 20 63 6d 64 2c 20 6e 75 6d 2c 20 70 74 72 29 , cmd, num, ptr)
0e50: 3b 0a 0a 20 20 20 20 73 77 69 74 63 68 20 28 63 ;.. switch (c
0e60: 6d 64 29 20 7b 0a 09 63 61 73 65 20 42 49 4f 5f md) {..case BIO_
0e70: 43 54 52 4c 5f 52 45 53 45 54 3a 0a 09 09 64 70 CTRL_RESET:...dp
0e80: 72 69 6e 74 66 28 22 47 6f 74 20 42 49 4f 5f 43 rintf("Got BIO_C
0e90: 54 52 4c 5f 52 45 53 45 54 22 29 3b 0a 09 09 6e TRL_RESET");...n
0ea0: 75 6d 20 3d 20 30 3b 0a 09 09 72 65 74 20 3d 20 um = 0;...ret =
0eb0: 30 3b 0a 09 09 62 72 65 61 6b 3b 0a 09 63 61 73 0;...break;..cas
0ec0: 65 20 42 49 4f 5f 43 5f 46 49 4c 45 5f 53 45 45 e BIO_C_FILE_SEE
0ed0: 4b 3a 0a 09 09 64 70 72 69 6e 74 66 28 22 47 6f K:...dprintf("Go
0ee0: 74 20 42 49 4f 5f 43 5f 46 49 4c 45 5f 53 45 45 t BIO_C_FILE_SEE
0ef0: 4b 22 29 3b 0a 09 09 72 65 74 20 3d 20 30 3b 0a K");...ret = 0;.
0f00: 09 09 62 72 65 61 6b 3b 0a 09 63 61 73 65 20 42 ..break;..case B
0f10: 49 4f 5f 43 5f 46 49 4c 45 5f 54 45 4c 4c 3a 0a IO_C_FILE_TELL:.
0f20: 09 09 64 70 72 69 6e 74 66 28 22 47 6f 74 20 42 ..dprintf("Got B
0f30: 49 4f 5f 43 5f 46 49 4c 45 5f 54 45 4c 4c 22 29 IO_C_FILE_TELL")
0f40: 3b 0a 09 09 72 65 74 20 3d 20 30 3b 0a 09 09 62 ;...ret = 0;...b
0f50: 72 65 61 6b 3b 0a 09 63 61 73 65 20 42 49 4f 5f reak;..case BIO_
0f60: 43 54 52 4c 5f 49 4e 46 4f 3a 0a 09 09 64 70 72 CTRL_INFO:...dpr
0f70: 69 6e 74 66 28 22 47 6f 74 20 42 49 4f 5f 43 54 intf("Got BIO_CT
0f80: 52 4c 5f 49 4e 46 4f 22 29 3b 0a 09 09 72 65 74 RL_INFO");...ret
0f90: 20 3d 20 31 3b 0a 09 09 62 72 65 61 6b 3b 0a 09 = 1;...break;..
0fa0: 63 61 73 65 20 42 49 4f 5f 43 5f 53 45 54 5f 46 case BIO_C_SET_F
0fb0: 44 3a 0a 09 09 64 70 72 69 6e 74 66 28 22 55 6e D:...dprintf("Un
0fc0: 73 75 70 70 6f 72 74 65 64 20 63 61 6c 6c 3a 20 supported call:
0fd0: 42 49 4f 5f 43 5f 53 45 54 5f 46 44 22 29 3b 0a BIO_C_SET_FD");.
0fe0: 09 09 72 65 74 20 3d 20 2d 31 3b 0a 09 09 62 72 ..ret = -1;...br
0ff0: 65 61 6b 3b 0a 09 63 61 73 65 20 42 49 4f 5f 43 eak;..case BIO_C
1000: 5f 47 45 54 5f 46 44 3a 0a 09 09 64 70 72 69 6e _GET_FD:...dprin
1010: 74 66 28 22 55 6e 73 75 70 70 6f 72 74 65 64 20 tf("Unsupported
1020: 63 61 6c 6c 3a 20 42 49 4f 5f 43 5f 47 45 54 5f call: BIO_C_GET_
1030: 46 44 22 29 3b 0a 09 09 72 65 74 20 3d 20 2d 31 FD");...ret = -1
1040: 3b 0a 09 09 62 72 65 61 6b 3b 0a 09 63 61 73 65 ;...break;..case
1050: 20 42 49 4f 5f 43 54 52 4c 5f 47 45 54 5f 43 4c BIO_CTRL_GET_CL
1060: 4f 53 45 3a 0a 09 09 64 70 72 69 6e 74 66 28 22 OSE:...dprintf("
1070: 47 6f 74 20 42 49 4f 5f 43 54 52 4c 5f 43 4c 4f Got BIO_CTRL_CLO
1080: 53 45 22 29 3b 0a 09 09 72 65 74 20 3d 20 42 49 SE");...ret = BI
1090: 4f 5f 67 65 74 5f 73 68 75 74 64 6f 77 6e 28 62 O_get_shutdown(b
10a0: 69 6f 29 3b 0a 09 09 62 72 65 61 6b 3b 0a 09 63 io);...break;..c
10b0: 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f 53 45 54 ase BIO_CTRL_SET
10c0: 5f 43 4c 4f 53 45 3a 0a 09 09 64 70 72 69 6e 74 _CLOSE:...dprint
10d0: 66 28 22 47 6f 74 20 42 49 4f 5f 53 45 54 5f 43 f("Got BIO_SET_C
10e0: 4c 4f 53 45 22 29 3b 0a 09 09 42 49 4f 5f 73 65 LOSE");...BIO_se
10f0: 74 5f 73 68 75 74 64 6f 77 6e 28 62 69 6f 2c 20 t_shutdown(bio,
1100: 6e 75 6d 29 3b 0a 09 09 62 72 65 61 6b 3b 0a 09 num);...break;..
1110: 63 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f 45 4f case BIO_CTRL_EO
1120: 46 3a 0a 09 09 64 70 72 69 6e 74 66 28 22 47 6f F:...dprintf("Go
1130: 74 20 42 49 4f 5f 43 54 52 4c 5f 45 4f 46 22 29 t BIO_CTRL_EOF")
1140: 3b 0a 09 09 72 65 74 20 3d 20 28 28 63 68 61 6e ;...ret = ((chan
1150: 29 20 3f 20 54 63 6c 5f 45 6f 66 28 63 68 61 6e ) ? Tcl_Eof(chan
1160: 29 20 3a 20 31 29 3b 0a 09 09 62 72 65 61 6b 3b ) : 1);...break;
1170: 0a 09 63 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f ..case BIO_CTRL_
1180: 50 45 4e 44 49 4e 47 3a 0a 09 09 64 70 72 69 6e PENDING:...dprin
1190: 74 66 28 22 47 6f 74 20 42 49 4f 5f 43 54 52 4c tf("Got BIO_CTRL
11a0: 5f 50 45 4e 44 49 4e 47 22 29 3b 0a 09 09 72 65 _PENDING");...re
11b0: 74 20 3d 20 28 28 63 68 61 6e 29 20 3f 20 28 28 t = ((chan) ? ((
11c0: 54 63 6c 5f 49 6e 70 75 74 42 75 66 66 65 72 65 Tcl_InputBuffere
11d0: 64 28 63 68 61 6e 29 20 3f 20 31 20 3a 20 30 29 d(chan) ? 1 : 0)
11e0: 29 20 3a 20 30 29 3b 0a 09 09 64 70 72 69 6e 74 ) : 0);...dprint
11f0: 66 28 22 42 49 4f 5f 43 54 52 4c 5f 50 45 4e 44 f("BIO_CTRL_PEND
1200: 49 4e 47 28 25 64 29 22 2c 20 28 69 6e 74 29 20 ING(%d)", (int)
1210: 72 65 74 29 3b 0a 09 09 62 72 65 61 6b 3b 0a 09 ret);...break;..
1220: 63 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f 57 50 case BIO_CTRL_WP
1230: 45 4e 44 49 4e 47 3a 0a 09 09 64 70 72 69 6e 74 ENDING:...dprint
1240: 66 28 22 47 6f 74 20 42 49 4f 5f 43 54 52 4c 5f f("Got BIO_CTRL_
1250: 57 50 45 4e 44 49 4e 47 22 29 3b 0a 09 09 72 65 WPENDING");...re
1260: 74 20 3d 20 30 3b 0a 09 09 62 72 65 61 6b 3b 0a t = 0;...break;.
1270: 09 63 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f 44 .case BIO_CTRL_D
1280: 55 50 3a 0a 09 09 64 70 72 69 6e 74 66 28 22 47 UP:...dprintf("G
1290: 6f 74 20 42 49 4f 5f 43 54 52 4c 5f 44 55 50 22 ot BIO_CTRL_DUP"
12a0: 29 3b 0a 09 09 62 72 65 61 6b 3b 0a 09 63 61 73 );...break;..cas
12b0: 65 20 42 49 4f 5f 43 54 52 4c 5f 46 4c 55 53 48 e BIO_CTRL_FLUSH
12c0: 3a 0a 09 09 64 70 72 69 6e 74 66 28 22 47 6f 74 :...dprintf("Got
12d0: 20 42 49 4f 5f 43 54 52 4c 5f 46 4c 55 53 48 22 BIO_CTRL_FLUSH"
12e0: 29 3b 0a 09 09 72 65 74 20 3d 20 28 28 63 68 61 );...ret = ((cha
12f0: 6e 29 20 26 26 20 28 54 63 6c 5f 57 72 69 74 65 n) && (Tcl_Write
1300: 52 61 77 28 63 68 61 6e 2c 20 22 22 2c 20 30 29 Raw(chan, "", 0)
1310: 20 3e 3d 20 30 29 20 3f 20 31 20 3a 20 2d 31 29 >= 0) ? 1 : -1)
1320: 3b 0a 09 09 64 70 72 69 6e 74 66 28 22 42 49 4f ;...dprintf("BIO
1330: 5f 43 54 52 4c 5f 46 4c 55 53 48 20 72 65 74 75 _CTRL_FLUSH retu
1340: 72 6e 69 6e 67 20 76 61 6c 75 65 20 25 6c 69 22 rning value %li"
1350: 2c 20 72 65 74 29 3b 0a 09 09 62 72 65 61 6b 3b , ret);...break;
1360: 0a 09 63 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f ..case BIO_CTRL_
1370: 50 55 53 48 3a 0a 09 09 64 70 72 69 6e 74 66 28 PUSH:...dprintf(
1380: 22 47 6f 74 20 42 49 4f 5f 43 54 52 4c 5f 50 55 "Got BIO_CTRL_PU
1390: 53 48 22 29 3b 0a 09 09 72 65 74 20 3d 20 30 3b SH");...ret = 0;
13a0: 0a 09 09 62 72 65 61 6b 3b 0a 09 63 61 73 65 20 ...break;..case
13b0: 42 49 4f 5f 43 54 52 4c 5f 50 4f 50 3a 0a 09 09 BIO_CTRL_POP:...
13c0: 64 70 72 69 6e 74 66 28 22 47 6f 74 20 42 49 4f dprintf("Got BIO
13d0: 5f 43 54 52 4c 5f 50 4f 50 22 29 3b 0a 09 09 72 _CTRL_POP");...r
13e0: 65 74 20 3d 20 30 3b 0a 09 09 62 72 65 61 6b 3b et = 0;...break;
13f0: 0a 09 63 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f ..case BIO_CTRL_
1400: 53 45 54 3a 0a 09 09 64 70 72 69 6e 74 66 28 22 SET:...dprintf("
1410: 47 6f 74 20 42 49 4f 5f 43 54 52 4c 5f 53 45 54 Got BIO_CTRL_SET
1420: 22 29 3b 0a 09 09 72 65 74 20 3d 20 30 3b 0a 09 ");...ret = 0;..
1430: 09 62 72 65 61 6b 3b 0a 09 63 61 73 65 20 42 49 .break;..case BI
1440: 4f 5f 43 54 52 4c 5f 47 45 54 20 3a 0a 09 09 64 O_CTRL_GET :...d
1450: 70 72 69 6e 74 66 28 22 47 6f 74 20 42 49 4f 5f printf("Got BIO_
1460: 43 54 52 4c 5f 47 45 54 20 22 29 3b 0a 09 09 72 CTRL_GET ");...r
1470: 65 74 20 3d 20 30 3b 0a 09 09 62 72 65 61 6b 3b et = 0;...break;
1480: 0a 23 69 66 64 65 66 20 42 49 4f 5f 43 54 52 4c .#ifdef BIO_CTRL
1490: 5f 47 45 54 5f 4b 54 4c 53 5f 53 45 4e 44 0a 09 _GET_KTLS_SEND..
14a0: 63 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f 47 45 case BIO_CTRL_GE
14b0: 54 5f 4b 54 4c 53 5f 53 45 4e 44 3a 0a 09 09 64 T_KTLS_SEND:...d
14c0: 70 72 69 6e 74 66 28 22 47 6f 74 20 42 49 4f 5f printf("Got BIO_
14d0: 43 54 52 4c 5f 47 45 54 5f 4b 54 4c 53 5f 53 45 CTRL_GET_KTLS_SE
14e0: 4e 44 22 29 3b 0a 09 09 72 65 74 20 3d 20 30 3b ND");...ret = 0;
14f0: 0a 09 09 62 72 65 61 6b 3b 0a 23 65 6e 64 69 66 ...break;.#endif
1500: 0a 23 69 66 64 65 66 20 42 49 4f 5f 43 54 52 4c .#ifdef BIO_CTRL
1510: 5f 47 45 54 5f 4b 54 4c 53 5f 52 45 43 56 0a 09 _GET_KTLS_RECV..
1520: 63 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f 47 45 case BIO_CTRL_GE
1530: 54 5f 4b 54 4c 53 5f 52 45 43 56 3a 0a 09 09 64 T_KTLS_RECV:...d
1540: 70 72 69 6e 74 66 28 22 47 6f 74 20 42 49 4f 5f printf("Got BIO_
1550: 43 54 52 4c 5f 47 45 54 5f 4b 54 4c 53 5f 52 45 CTRL_GET_KTLS_RE
1560: 43 56 22 29 3b 0a 09 09 72 65 74 20 3d 20 30 3b CV");...ret = 0;
1570: 0a 09 09 62 72 65 61 6b 3b 0a 23 65 6e 64 69 66 ...break;.#endif
1580: 0a 09 64 65 66 61 75 6c 74 3a 0a 09 09 64 70 72 ..default:...dpr
1590: 69 6e 74 66 28 22 47 6f 74 20 75 6e 6b 6e 6f 77 intf("Got unknow
15a0: 6e 20 63 6f 6e 74 72 6f 6c 20 63 6f 6d 6d 61 6e n control comman
15b0: 64 20 28 25 69 29 22 2c 20 63 6d 64 29 3b 0a 09 d (%i)", cmd);..
15c0: 09 72 65 74 20 3d 20 30 3b 0a 09 09 62 72 65 61 .ret = 0;...brea
15d0: 6b 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72 65 74 k;. }. ret
15e0: 75 72 6e 28 72 65 74 29 3b 0a 7d 0a 0a 73 74 61 urn(ret);.}..sta
15f0: 74 69 63 20 69 6e 74 20 42 69 6f 4e 65 77 28 42 tic int BioNew(B
1600: 49 4f 20 2a 62 69 6f 29 20 7b 0a 20 20 20 20 64 IO *bio) {. d
1610: 70 72 69 6e 74 66 28 22 42 69 6f 4e 65 77 28 25 printf("BioNew(%
1620: 70 29 20 63 61 6c 6c 65 64 22 2c 20 62 69 6f 29 p) called", bio)
1630: 3b 0a 0a 20 20 20 20 42 49 4f 5f 73 65 74 5f 69 ;.. BIO_set_i
1640: 6e 69 74 28 62 69 6f 2c 20 30 29 3b 0a 20 20 20 nit(bio, 0);.
1650: 20 42 49 4f 5f 73 65 74 5f 64 61 74 61 28 62 69 BIO_set_data(bi
1660: 6f 2c 20 4e 55 4c 4c 29 3b 0a 20 20 20 20 42 49 o, NULL);. BI
1670: 4f 5f 63 6c 65 61 72 5f 66 6c 61 67 73 28 62 69 O_clear_flags(bi
1680: 6f 2c 20 2d 31 29 3b 0a 20 20 20 20 72 65 74 75 o, -1);. retu
1690: 72 6e 28 31 29 3b 0a 7d 0a 0a 73 74 61 74 69 63 rn(1);.}..static
16a0: 20 69 6e 74 20 42 69 6f 46 72 65 65 28 42 49 4f int BioFree(BIO
16b0: 20 2a 62 69 6f 29 20 7b 0a 20 20 20 20 69 66 20 *bio) {. if
16c0: 28 62 69 6f 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a (bio == NULL) {.
16d0: 09 72 65 74 75 72 6e 28 30 29 3b 0a 20 20 20 20 .return(0);.
16e0: 7d 0a 0a 20 20 20 20 64 70 72 69 6e 74 66 28 22 }.. dprintf("
16f0: 42 69 6f 46 72 65 65 28 25 70 29 20 63 61 6c 6c BioFree(%p) call
1700: 65 64 22 2c 20 62 69 6f 29 3b 0a 0a 20 20 20 20 ed", bio);..
1710: 69 66 20 28 42 49 4f 5f 67 65 74 5f 73 68 75 74 if (BIO_get_shut
1720: 64 6f 77 6e 28 62 69 6f 29 29 20 7b 0a 09 69 66 down(bio)) {..if
1730: 20 28 42 49 4f 5f 67 65 74 5f 69 6e 69 74 28 62 (BIO_get_init(b
1740: 69 6f 29 29 20 7b 0a 09 20 20 20 20 2f 2a 73 68 io)) {.. /*sh
1750: 75 74 64 6f 77 6e 28 62 69 6f 2d 3e 6e 75 6d 2c utdown(bio->num,
1760: 20 32 29 20 2a 2f 0a 09 20 20 20 20 2f 2a 63 6c 2) */.. /*cl
1770: 6f 73 65 73 6f 63 6b 65 74 28 62 69 6f 2d 3e 6e osesocket(bio->n
1780: 75 6d 29 20 2a 2f 0a 09 7d 0a 0a 09 42 49 4f 5f um) */..}...BIO_
1790: 73 65 74 5f 69 6e 69 74 28 62 69 6f 2c 20 30 29 set_init(bio, 0)
17a0: 3b 0a 09 42 49 4f 5f 63 6c 65 61 72 5f 66 6c 61 ;..BIO_clear_fla
17b0: 67 73 28 62 69 6f 2c 20 2d 31 29 3b 0a 20 20 20 gs(bio, -1);.
17c0: 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 28 31 29 }. return(1)
17d0: 3b 0a 7d 0a 0a 42 49 4f 20 2a 42 49 4f 5f 6e 65 ;.}..BIO *BIO_ne
17e0: 77 5f 74 63 6c 28 53 74 61 74 65 20 2a 73 74 61 w_tcl(State *sta
17f0: 74 65 50 74 72 2c 20 69 6e 74 20 66 6c 61 67 73 tePtr, int flags
1800: 29 20 7b 0a 20 20 20 20 42 49 4f 20 2a 62 69 6f ) {. BIO *bio
1810: 3b 0a 20 20 20 20 73 74 61 74 69 63 20 42 49 4f ;. static BIO
1820: 5f 4d 45 54 48 4f 44 20 2a 42 69 6f 4d 65 74 68 _METHOD *BioMeth
1830: 6f 64 73 20 3d 20 4e 55 4c 4c 3b 0a 23 69 66 64 ods = NULL;.#ifd
1840: 65 66 20 54 43 4c 54 4c 53 5f 53 53 4c 5f 55 53 ef TCLTLS_SSL_US
1850: 45 5f 46 41 53 54 50 41 54 48 0a 20 20 20 20 54 E_FASTPATH. T
1860: 63 6c 5f 43 68 61 6e 6e 65 6c 20 70 61 72 65 6e cl_Channel paren
1870: 74 43 68 61 6e 6e 65 6c 3b 0a 20 20 20 20 63 6f tChannel;. co
1880: 6e 73 74 20 54 63 6c 5f 43 68 61 6e 6e 65 6c 54 nst Tcl_ChannelT
1890: 79 70 65 20 2a 70 61 72 65 6e 74 43 68 61 6e 6e ype *parentChann
18a0: 65 6c 54 79 70 65 3b 0a 20 20 20 20 76 6f 69 64 elType;. void
18b0: 20 2a 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c 46 *parentChannelF
18c0: 64 49 6e 5f 70 2c 20 2a 70 61 72 65 6e 74 43 68 dIn_p, *parentCh
18d0: 61 6e 6e 65 6c 46 64 4f 75 74 5f 70 3b 0a 20 20 annelFdOut_p;.
18e0: 20 20 69 6e 74 20 70 61 72 65 6e 74 43 68 61 6e int parentChan
18f0: 6e 65 6c 46 64 49 6e 2c 20 70 61 72 65 6e 74 43 nelFdIn, parentC
1900: 68 61 6e 6e 65 6c 46 64 4f 75 74 2c 20 70 61 72 hannelFdOut, par
1910: 65 6e 74 43 68 61 6e 6e 65 6c 46 64 3b 0a 20 20 entChannelFd;.
1920: 20 20 69 6e 74 20 76 61 6c 69 64 50 61 72 65 6e int validParen
1930: 74 43 68 61 6e 6e 65 6c 46 64 3b 0a 20 20 20 20 tChannelFd;.
1940: 69 6e 74 20 74 63 6c 47 65 74 43 68 61 6e 6e 65 int tclGetChanne
1950: 6c 48 61 6e 64 6c 65 52 65 74 3b 0a 23 65 6e 64 lHandleRet;.#end
1960: 69 66 0a 0a 20 20 20 20 64 70 72 69 6e 74 66 28 if.. dprintf(
1970: 22 42 49 4f 5f 6e 65 77 5f 74 63 6c 28 29 20 63 "BIO_new_tcl() c
1980: 61 6c 6c 65 64 22 29 3b 0a 0a 20 20 20 20 69 66 alled");.. if
1990: 20 28 42 69 6f 4d 65 74 68 6f 64 73 20 3d 3d 20 (BioMethods ==
19a0: 4e 55 4c 4c 29 20 7b 0a 09 42 69 6f 4d 65 74 68 NULL) {..BioMeth
19b0: 6f 64 73 20 3d 20 42 49 4f 5f 6d 65 74 68 5f 6e ods = BIO_meth_n
19c0: 65 77 28 42 49 4f 5f 54 59 50 45 5f 54 43 4c 2c ew(BIO_TYPE_TCL,
19d0: 20 22 74 63 6c 22 29 3b 0a 09 42 49 4f 5f 6d 65 "tcl");..BIO_me
19e0: 74 68 5f 73 65 74 5f 77 72 69 74 65 28 42 69 6f th_set_write(Bio
19f0: 4d 65 74 68 6f 64 73 2c 20 42 69 6f 57 72 69 74 Methods, BioWrit
1a00: 65 29 3b 0a 09 42 49 4f 5f 6d 65 74 68 5f 73 65 e);..BIO_meth_se
1a10: 74 5f 72 65 61 64 28 42 69 6f 4d 65 74 68 6f 64 t_read(BioMethod
1a20: 73 2c 20 42 69 6f 52 65 61 64 29 3b 0a 09 42 49 s, BioRead);..BI
1a30: 4f 5f 6d 65 74 68 5f 73 65 74 5f 70 75 74 73 28 O_meth_set_puts(
1a40: 42 69 6f 4d 65 74 68 6f 64 73 2c 20 42 69 6f 50 BioMethods, BioP
1a50: 75 74 73 29 3b 0a 09 42 49 4f 5f 6d 65 74 68 5f uts);..BIO_meth_
1a60: 73 65 74 5f 63 74 72 6c 28 42 69 6f 4d 65 74 68 set_ctrl(BioMeth
1a70: 6f 64 73 2c 20 42 69 6f 43 74 72 6c 29 3b 0a 09 ods, BioCtrl);..
1a80: 42 49 4f 5f 6d 65 74 68 5f 73 65 74 5f 63 72 65 BIO_meth_set_cre
1a90: 61 74 65 28 42 69 6f 4d 65 74 68 6f 64 73 2c 20 ate(BioMethods,
1aa0: 42 69 6f 4e 65 77 29 3b 0a 09 42 49 4f 5f 6d 65 BioNew);..BIO_me
1ab0: 74 68 5f 73 65 74 5f 64 65 73 74 72 6f 79 28 42 th_set_destroy(B
1ac0: 69 6f 4d 65 74 68 6f 64 73 2c 20 42 69 6f 46 72 ioMethods, BioFr
1ad0: 65 65 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 ee);. }..
1ae0: 69 66 20 28 73 74 61 74 65 50 74 72 20 3d 3d 20 if (statePtr ==
1af0: 4e 55 4c 4c 29 20 7b 0a 09 64 70 72 69 6e 74 66 NULL) {..dprintf
1b00: 28 22 41 73 6b 65 64 20 74 6f 20 73 65 74 75 70 ("Asked to setup
1b10: 20 61 20 4e 55 4c 4c 20 73 74 61 74 65 2c 20 6a a NULL state, j
1b20: 75 73 74 20 63 72 65 61 74 69 6e 67 20 74 68 65 ust creating the
1b30: 20 69 6e 69 74 69 61 6c 20 63 6f 6e 66 69 67 75 initial configu
1b40: 72 61 74 69 6f 6e 22 29 3b 0a 0a 09 72 65 74 75 ration");...retu
1b50: 72 6e 28 4e 55 4c 4c 29 3b 0a 20 20 20 20 7d 0a rn(NULL);. }.
1b60: 0a 23 69 66 64 65 66 20 54 43 4c 54 4c 53 5f 53 .#ifdef TCLTLS_S
1b70: 53 4c 5f 55 53 45 5f 46 41 53 54 50 41 54 48 0a SL_USE_FASTPATH.
1b80: 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 49 66 /*. * If
1b90: 20 74 68 65 20 63 68 61 6e 6e 65 6c 20 63 61 6e the channel can
1ba0: 20 62 65 20 6d 61 70 70 65 64 20 62 61 63 6b 20 be mapped back
1bb0: 74 6f 20 61 20 66 69 6c 65 20 64 65 73 63 72 69 to a file descri
1bc0: 70 74 6f 72 2c 20 6a 75 73 74 20 75 73 65 20 74 ptor, just use t
1bd0: 68 65 20 66 69 6c 65 20 64 65 73 63 72 69 70 74 he file descript
1be0: 6f 72 0a 20 20 20 20 20 2a 20 77 69 74 68 20 74 or. * with t
1bf0: 68 65 20 53 53 4c 20 6c 69 62 72 61 72 79 20 73 he SSL library s
1c00: 69 6e 63 65 20 69 74 20 77 69 6c 6c 20 6c 69 6b ince it will lik
1c10: 65 6c 79 20 62 65 20 6f 70 74 69 6d 69 7a 65 64 ely be optimized
1c20: 20 66 6f 72 20 74 68 69 73 2e 0a 20 20 20 20 20 for this..
1c30: 2a 2f 0a 20 20 20 20 70 61 72 65 6e 74 43 68 61 */. parentCha
1c40: 6e 6e 65 6c 20 3d 20 54 6c 73 5f 47 65 74 50 61 nnel = Tls_GetPa
1c50: 72 65 6e 74 28 73 74 61 74 65 50 74 72 2c 20 30 rent(statePtr, 0
1c60: 29 3b 0a 20 20 20 20 70 61 72 65 6e 74 43 68 61 );. parentCha
1c70: 6e 6e 65 6c 54 79 70 65 20 3d 20 54 63 6c 5f 47 nnelType = Tcl_G
1c80: 65 74 43 68 61 6e 6e 65 6c 54 79 70 65 28 70 61 etChannelType(pa
1c90: 72 65 6e 74 43 68 61 6e 6e 65 6c 29 3b 0a 0a 20 rentChannel);..
1ca0: 20 20 20 76 61 6c 69 64 50 61 72 65 6e 74 43 68 validParentCh
1cb0: 61 6e 6e 65 6c 46 64 20 3d 20 30 3b 0a 20 20 20 annelFd = 0;.
1cc0: 20 69 66 20 28 73 74 72 63 6d 70 28 70 61 72 65 if (strcmp(pare
1cd0: 6e 74 43 68 61 6e 6e 65 6c 54 79 70 65 2d 3e 74 ntChannelType->t
1ce0: 79 70 65 4e 61 6d 65 2c 20 22 74 63 70 22 29 20 ypeName, "tcp")
1cf0: 3d 3d 20 30 29 20 7b 0a 09 74 63 6c 47 65 74 43 == 0) {..tclGetC
1d00: 68 61 6e 6e 65 6c 48 61 6e 64 6c 65 52 65 74 20 hannelHandleRet
1d10: 3d 20 54 63 6c 5f 47 65 74 43 68 61 6e 6e 65 6c = Tcl_GetChannel
1d20: 48 61 6e 64 6c 65 28 70 61 72 65 6e 74 43 68 61 Handle(parentCha
1d30: 6e 6e 65 6c 2c 20 54 43 4c 5f 52 45 41 44 41 42 nnel, TCL_READAB
1d40: 4c 45 2c 20 28 43 6c 69 65 6e 74 44 61 74 61 29 LE, (ClientData)
1d50: 20 26 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c 46 &parentChannelF
1d60: 64 49 6e 5f 70 29 3b 0a 09 69 66 20 28 74 63 6c dIn_p);..if (tcl
1d70: 47 65 74 43 68 61 6e 6e 65 6c 48 61 6e 64 6c 65 GetChannelHandle
1d80: 52 65 74 20 3d 3d 20 54 43 4c 5f 4f 4b 29 20 7b Ret == TCL_OK) {
1d90: 0a 09 20 20 20 20 74 63 6c 47 65 74 43 68 61 6e .. tclGetChan
1da0: 6e 65 6c 48 61 6e 64 6c 65 52 65 74 20 3d 20 54 nelHandleRet = T
1db0: 63 6c 5f 47 65 74 43 68 61 6e 6e 65 6c 48 61 6e cl_GetChannelHan
1dc0: 64 6c 65 28 70 61 72 65 6e 74 43 68 61 6e 6e 65 dle(parentChanne
1dd0: 6c 2c 20 54 43 4c 5f 57 52 49 54 41 42 4c 45 2c l, TCL_WRITABLE,
1de0: 20 28 43 6c 69 65 6e 74 44 61 74 61 29 20 26 70 (ClientData) &p
1df0: 61 72 65 6e 74 43 68 61 6e 6e 65 6c 46 64 4f 75 arentChannelFdOu
1e00: 74 5f 70 29 3b 0a 09 20 20 20 20 69 66 20 28 74 t_p);.. if (t
1e10: 63 6c 47 65 74 43 68 61 6e 6e 65 6c 48 61 6e 64 clGetChannelHand
1e20: 6c 65 52 65 74 20 3d 3d 20 54 43 4c 5f 4f 4b 29 leRet == TCL_OK)
1e30: 20 7b 0a 09 09 70 61 72 65 6e 74 43 68 61 6e 6e {...parentChann
1e40: 65 6c 46 64 49 6e 20 3d 20 50 54 52 32 49 4e 54 elFdIn = PTR2INT
1e50: 28 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c 46 64 (parentChannelFd
1e60: 49 6e 5f 70 29 3b 0a 09 09 70 61 72 65 6e 74 43 In_p);...parentC
1e70: 68 61 6e 6e 65 6c 46 64 4f 75 74 20 3d 20 50 54 hannelFdOut = PT
1e80: 52 32 49 4e 54 28 70 61 72 65 6e 74 43 68 61 6e R2INT(parentChan
1e90: 6e 65 6c 46 64 4f 75 74 5f 70 29 3b 0a 09 09 69 nelFdOut_p);...i
1ea0: 66 20 28 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c f (parentChannel
1eb0: 46 64 49 6e 20 3d 3d 20 70 61 72 65 6e 74 43 68 FdIn == parentCh
1ec0: 61 6e 6e 65 6c 46 64 4f 75 74 29 20 7b 0a 09 09 annelFdOut) {...
1ed0: 20 20 20 20 70 61 72 65 6e 74 43 68 61 6e 6e 65 parentChanne
1ee0: 6c 46 64 20 3d 20 70 61 72 65 6e 74 43 68 61 6e lFd = parentChan
1ef0: 6e 65 6c 46 64 49 6e 3b 0a 09 09 20 20 20 20 76 nelFdIn;... v
1f00: 61 6c 69 64 50 61 72 65 6e 74 43 68 61 6e 6e 65 alidParentChanne
1f10: 6c 46 64 20 3d 20 31 3b 0a 09 09 7d 0a 09 20 20 lFd = 1;...}..
1f20: 20 20 7d 0a 09 7d 0a 20 20 20 20 7d 0a 0a 20 20 }..}. }..
1f30: 20 20 69 66 20 28 76 61 6c 69 64 50 61 72 65 6e if (validParen
1f40: 74 43 68 61 6e 6e 65 6c 46 64 29 20 7b 0a 09 64 tChannelFd) {..d
1f50: 70 72 69 6e 74 66 28 22 57 65 20 66 6f 75 6e 64 printf("We found
1f60: 20 61 20 73 68 6f 72 74 63 75 74 2c 20 74 68 69 a shortcut, thi
1f70: 73 20 63 68 61 6e 6e 65 6c 20 69 73 20 62 61 63 s channel is bac
1f80: 6b 65 64 20 62 79 20 61 20 73 6f 63 6b 65 74 3a ked by a socket:
1f90: 20 25 69 22 2c 20 70 61 72 65 6e 74 43 68 61 6e %i", parentChan
1fa0: 6e 65 6c 46 64 49 6e 29 3b 0a 09 62 69 6f 20 3d nelFdIn);..bio =
1fb0: 20 42 49 4f 5f 6e 65 77 5f 73 6f 63 6b 65 74 28 BIO_new_socket(
1fc0: 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c 46 64 2c parentChannelFd,
1fd0: 20 66 6c 61 67 73 29 3b 0a 09 73 74 61 74 65 50 flags);..stateP
1fe0: 74 72 2d 3e 66 6c 61 67 73 20 7c 3d 20 54 4c 53 tr->flags |= TLS
1ff0: 5f 54 43 4c 5f 46 41 53 54 50 41 54 48 3b 0a 09 _TCL_FASTPATH;..
2000: 72 65 74 75 72 6e 28 62 69 6f 29 3b 0a 20 20 20 return(bio);.
2010: 20 7d 0a 0a 20 20 20 20 64 70 72 69 6e 74 66 28 }.. dprintf(
2020: 22 46 61 6c 6c 69 6e 67 20 62 61 63 6b 20 74 6f "Falling back to
2030: 20 54 63 6c 20 49 2f 4f 20 66 6f 72 20 74 68 69 Tcl I/O for thi
2040: 73 20 63 68 61 6e 6e 65 6c 22 29 3b 0a 23 65 6e s channel");.#en
2050: 64 69 66 0a 0a 20 20 20 20 62 69 6f 20 3d 20 42 dif.. bio = B
2060: 49 4f 5f 6e 65 77 28 42 69 6f 4d 65 74 68 6f 64 IO_new(BioMethod
2070: 73 29 3b 0a 20 20 20 20 42 49 4f 5f 73 65 74 5f s);. BIO_set_
2080: 64 61 74 61 28 62 69 6f 2c 20 73 74 61 74 65 50 data(bio, stateP
2090: 74 72 29 3b 0a 20 20 20 20 42 49 4f 5f 73 65 74 tr);. BIO_set
20a0: 5f 73 68 75 74 64 6f 77 6e 28 62 69 6f 2c 20 66 _shutdown(bio, f
20b0: 6c 61 67 73 29 3b 0a 20 20 20 20 42 49 4f 5f 73 lags);. BIO_s
20c0: 65 74 5f 69 6e 69 74 28 62 69 6f 2c 20 31 29 3b et_init(bio, 1);
20d0: 0a 20 20 20 20 72 65 74 75 72 6e 28 62 69 6f 29 . return(bio)
20e0: 3b 0a 7d 0a ;.}.