0000: 2f 2a 0a 20 2a 20 43 6f 70 79 72 69 67 68 74 20 /*. * Copyright
0010: 28 43 29 20 31 39 39 37 2d 32 30 30 30 20 4d 61 (C) 1997-2000 Ma
0020: 74 74 20 4e 65 77 6d 61 6e 20 3c 6d 61 74 74 40 tt Newman <matt@
0030: 6e 6f 76 61 64 69 67 6d 2e 63 6f 6d 3e 0a 20 2a novadigm.com>. *
0040: 0a 20 2a 20 50 72 6f 76 69 64 65 73 20 42 49 4f . * Provides BIO
0050: 20 6c 61 79 65 72 20 74 6f 20 69 6e 74 65 72 66 layer to interf
0060: 61 63 65 20 6f 70 65 6e 73 73 6c 20 74 6f 20 54 ace openssl to T
0070: 63 6c 2e 0a 20 2a 2f 0a 0a 23 69 6e 63 6c 75 64 cl.. */..#includ
0080: 65 20 22 74 6c 73 49 6e 74 2e 68 22 0a 0a 73 74 e "tlsInt.h"..st
0090: 61 74 69 63 20 69 6e 74 20 42 69 6f 57 72 69 74 atic int BioWrit
00a0: 65 28 42 49 4f 20 2a 62 69 6f 2c 20 63 6f 6e 73 e(BIO *bio, cons
00b0: 74 20 63 68 61 72 20 2a 62 75 66 2c 20 69 6e 74 t char *buf, int
00c0: 20 62 75 66 4c 65 6e 29 20 7b 0a 20 20 20 20 54 bufLen) {. T
00d0: 63 6c 5f 43 68 61 6e 6e 65 6c 20 63 68 61 6e 3b cl_Channel chan;
00e0: 0a 20 20 20 20 54 63 6c 5f 53 69 7a 65 20 72 65 . Tcl_Size re
00f0: 74 3b 0a 20 20 20 20 69 6e 74 20 74 63 6c 45 6f t;. int tclEo
0100: 66 43 68 61 6e 2c 20 74 63 6c 45 72 72 6e 6f 3b fChan, tclErrno;
0110: 0a 0a 20 20 20 20 63 68 61 6e 20 3d 20 54 6c 73 .. chan = Tls
0120: 5f 47 65 74 50 61 72 65 6e 74 28 28 53 74 61 74 _GetParent((Stat
0130: 65 20 2a 29 20 42 49 4f 5f 67 65 74 5f 64 61 74 e *) BIO_get_dat
0140: 61 28 62 69 6f 29 2c 20 30 29 3b 0a 0a 20 20 20 a(bio), 0);..
0150: 20 64 70 72 69 6e 74 66 28 22 5b 63 68 61 6e 3d dprintf("[chan=
0160: 25 70 5d 20 42 69 6f 57 72 69 74 65 28 25 70 2c %p] BioWrite(%p,
0170: 20 3c 62 75 66 3e 2c 20 25 64 29 22 2c 20 28 76 <buf>, %d)", (v
0180: 6f 69 64 20 2a 29 63 68 61 6e 2c 20 28 76 6f 69 oid *)chan, (voi
0190: 64 20 2a 29 20 62 69 6f 2c 20 62 75 66 4c 65 6e d *) bio, bufLen
01a0: 29 3b 0a 0a 20 20 20 20 72 65 74 20 3d 20 54 63 );.. ret = Tc
01b0: 6c 5f 57 72 69 74 65 52 61 77 28 63 68 61 6e 2c l_WriteRaw(chan,
01c0: 20 62 75 66 2c 20 28 54 63 6c 5f 53 69 7a 65 29 buf, (Tcl_Size)
01d0: 20 62 75 66 4c 65 6e 29 3b 0a 0a 20 20 20 20 74 bufLen);.. t
01e0: 63 6c 45 6f 66 43 68 61 6e 20 3d 20 54 63 6c 5f clEofChan = Tcl_
01f0: 45 6f 66 28 63 68 61 6e 29 3b 0a 20 20 20 20 74 Eof(chan);. t
0200: 63 6c 45 72 72 6e 6f 20 3d 20 54 63 6c 5f 47 65 clErrno = Tcl_Ge
0210: 74 45 72 72 6e 6f 28 29 3b 0a 0a 20 20 20 20 64 tErrno();.. d
0220: 70 72 69 6e 74 66 28 22 5b 63 68 61 6e 3d 25 70 printf("[chan=%p
0230: 5d 20 42 69 6f 57 72 69 74 65 28 25 64 29 20 2d ] BioWrite(%d) -
0240: 3e 20 25 22 20 54 43 4c 5f 53 49 5a 45 5f 4d 4f > %" TCL_SIZE_MO
0250: 44 49 46 49 45 52 20 22 64 20 5b 74 63 6c 45 6f DIFIER "d [tclEo
0260: 66 3d 25 64 3b 20 74 63 6c 45 72 72 6e 6f 3d 25 f=%d; tclErrno=%
0270: 64 5d 22 2c 0a 09 28 76 6f 69 64 20 2a 29 20 63 d]",..(void *) c
0280: 68 61 6e 2c 20 62 75 66 4c 65 6e 2c 20 72 65 74 han, bufLen, ret
0290: 2c 20 74 63 6c 45 6f 66 43 68 61 6e 2c 20 54 63 , tclEofChan, Tc
02a0: 6c 5f 47 65 74 45 72 72 6e 6f 28 29 29 3b 0a 0a l_GetErrno());..
02b0: 20 20 20 20 42 49 4f 5f 63 6c 65 61 72 5f 66 6c BIO_clear_fl
02c0: 61 67 73 28 62 69 6f 2c 20 42 49 4f 5f 46 4c 41 ags(bio, BIO_FLA
02d0: 47 53 5f 57 52 49 54 45 20 7c 20 42 49 4f 5f 46 GS_WRITE | BIO_F
02e0: 4c 41 47 53 5f 53 48 4f 55 4c 44 5f 52 45 54 52 LAGS_SHOULD_RETR
02f0: 59 29 3b 0a 0a 20 20 20 20 69 66 20 28 74 63 6c Y);.. if (tcl
0300: 45 6f 66 43 68 61 6e 20 26 26 20 72 65 74 20 3c EofChan && ret <
0310: 3d 20 30 29 20 7b 0a 09 64 70 72 69 6e 74 66 28 = 0) {..dprintf(
0320: 22 47 6f 74 20 45 4f 46 20 77 68 69 6c 65 20 72 "Got EOF while r
0330: 65 61 64 69 6e 67 2c 20 72 65 74 75 72 6e 69 6e eading, returnin
0340: 67 20 61 20 43 6f 6e 6e 65 63 74 69 6f 6e 20 52 g a Connection R
0350: 65 73 65 74 20 65 72 72 6f 72 20 77 68 69 63 68 eset error which
0360: 20 6d 61 70 73 20 74 6f 20 53 6f 66 74 20 45 4f maps to Soft EO
0370: 46 22 29 3b 0a 09 54 63 6c 5f 53 65 74 45 72 72 F");..Tcl_SetErr
0380: 6e 6f 28 45 43 4f 4e 4e 52 45 53 45 54 29 3b 0a no(ECONNRESET);.
0390: 09 72 65 74 20 3d 20 30 3b 0a 0a 20 20 20 20 7d .ret = 0;.. }
03a0: 20 65 6c 73 65 20 69 66 20 28 72 65 74 20 3d 3d else if (ret ==
03b0: 20 30 29 20 7b 0a 09 64 70 72 69 6e 74 66 28 22 0) {..dprintf("
03c0: 47 6f 74 20 30 20 66 72 6f 6d 20 54 63 6c 5f 57 Got 0 from Tcl_W
03d0: 72 69 74 65 52 61 77 2c 20 61 6e 64 20 45 4f 46 riteRaw, and EOF
03e0: 20 69 73 20 6e 6f 74 20 73 65 74 3b 20 72 65 74 is not set; ret
03f0: 20 3d 20 30 22 29 3b 0a 09 64 70 72 69 6e 74 66 = 0");..dprintf
0400: 28 22 53 65 74 74 69 6e 67 20 72 65 74 72 79 20 ("Setting retry
0410: 72 65 61 64 20 66 6c 61 67 22 29 3b 0a 09 42 49 read flag");..BI
0420: 4f 5f 73 65 74 5f 72 65 74 72 79 5f 72 65 61 64 O_set_retry_read
0430: 28 62 69 6f 29 3b 0a 0a 20 20 20 20 7d 20 65 6c (bio);.. } el
0440: 73 65 20 69 66 20 28 72 65 74 20 3c 20 30 29 20 se if (ret < 0)
0450: 7b 0a 09 64 70 72 69 6e 74 66 28 22 57 65 20 67 {..dprintf("We g
0460: 6f 74 20 73 6f 6d 65 20 6b 69 6e 64 20 6f 66 20 ot some kind of
0470: 49 2f 4f 20 65 72 72 6f 72 22 29 3b 0a 0a 09 69 I/O error");...i
0480: 66 20 28 74 63 6c 45 72 72 6e 6f 20 3d 3d 20 45 f (tclErrno == E
0490: 41 47 41 49 4e 29 20 7b 0a 09 20 20 20 20 64 70 AGAIN) {.. dp
04a0: 72 69 6e 74 66 28 22 49 74 27 73 20 45 41 47 41 rintf("It's EAGA
04b0: 49 4e 22 29 3b 0a 09 7d 20 65 6c 73 65 20 7b 0a IN");..} else {.
04c0: 09 20 20 20 20 64 70 72 69 6e 74 66 28 22 49 74 . dprintf("It
04d0: 27 73 20 61 6e 20 75 6e 65 78 70 65 63 74 65 64 's an unexpected
04e0: 20 65 72 72 6f 72 3a 20 25 73 2f 25 69 22 2c 20 error: %s/%i",
04f0: 54 63 6c 5f 45 72 72 6e 6f 4d 73 67 28 74 63 6c Tcl_ErrnoMsg(tcl
0500: 45 72 72 6e 6f 29 2c 20 74 63 6c 45 72 72 6e 6f Errno), tclErrno
0510: 29 3b 0a 09 7d 0a 0a 20 20 20 20 7d 20 65 6c 73 );..}.. } els
0520: 65 20 7b 0a 09 64 70 72 69 6e 74 66 28 22 53 75 e {..dprintf("Su
0530: 63 63 65 73 73 66 75 6c 6c 79 20 77 72 6f 74 65 ccessfully wrote
0540: 20 73 6f 6d 65 20 64 61 74 61 22 29 3b 0a 20 20 some data");.
0550: 20 20 7d 0a 0a 20 20 20 20 69 66 20 28 72 65 74 }.. if (ret
0560: 20 21 3d 20 2d 31 20 7c 7c 20 28 72 65 74 20 3d != -1 || (ret =
0570: 3d 20 2d 31 20 26 26 20 74 63 6c 45 72 72 6e 6f = -1 && tclErrno
0580: 20 3d 3d 20 45 41 47 41 49 4e 29 29 20 7b 0a 09 == EAGAIN)) {..
0590: 69 66 20 28 42 49 4f 5f 73 68 6f 75 6c 64 5f 72 if (BIO_should_r
05a0: 65 61 64 28 62 69 6f 29 29 20 7b 0a 09 20 20 20 ead(bio)) {..
05b0: 20 64 70 72 69 6e 74 66 28 22 53 65 74 74 69 6e dprintf("Settin
05c0: 67 20 73 68 6f 75 6c 64 20 72 65 74 72 79 20 72 g should retry r
05d0: 65 61 64 20 66 6c 61 67 22 29 3b 0a 0a 09 20 20 ead flag");...
05e0: 20 20 42 49 4f 5f 73 65 74 5f 72 65 74 72 79 5f BIO_set_retry_
05f0: 72 65 61 64 28 62 69 6f 29 3b 0a 09 7d 0a 20 20 read(bio);..}.
0600: 20 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 28 28 }. return((
0610: 69 6e 74 29 20 72 65 74 29 3b 0a 7d 0a 0a 73 74 int) ret);.}..st
0620: 61 74 69 63 20 69 6e 74 20 42 69 6f 52 65 61 64 atic int BioRead
0630: 28 42 49 4f 20 2a 62 69 6f 2c 20 63 68 61 72 20 (BIO *bio, char
0640: 2a 62 75 66 2c 20 69 6e 74 20 62 75 66 4c 65 6e *buf, int bufLen
0650: 29 20 7b 0a 20 20 20 20 54 63 6c 5f 43 68 61 6e ) {. Tcl_Chan
0660: 6e 65 6c 20 63 68 61 6e 3b 0a 20 20 20 20 54 63 nel chan;. Tc
0670: 6c 5f 53 69 7a 65 20 72 65 74 20 3d 20 30 3b 0a l_Size ret = 0;.
0680: 20 20 20 20 69 6e 74 20 74 63 6c 45 6f 66 43 68 int tclEofCh
0690: 61 6e 2c 20 74 63 6c 45 72 72 6e 6f 3b 0a 0a 20 an, tclErrno;..
06a0: 20 20 20 63 68 61 6e 20 3d 20 54 6c 73 5f 47 65 chan = Tls_Ge
06b0: 74 50 61 72 65 6e 74 28 28 53 74 61 74 65 20 2a tParent((State *
06c0: 29 20 42 49 4f 5f 67 65 74 5f 64 61 74 61 28 62 ) BIO_get_data(b
06d0: 69 6f 29 2c 20 30 29 3b 0a 0a 20 20 20 20 64 70 io), 0);.. dp
06e0: 72 69 6e 74 66 28 22 5b 63 68 61 6e 3d 25 70 5d rintf("[chan=%p]
06f0: 20 42 69 6f 52 65 61 64 28 25 70 2c 20 3c 62 75 BioRead(%p, <bu
0700: 66 3e 2c 20 25 64 29 22 2c 20 28 76 6f 69 64 20 f>, %d)", (void
0710: 2a 29 20 63 68 61 6e 2c 20 28 76 6f 69 64 20 2a *) chan, (void *
0720: 29 20 62 69 6f 2c 20 62 75 66 4c 65 6e 29 3b 0a ) bio, bufLen);.
0730: 0a 20 20 20 20 69 66 20 28 62 75 66 20 3d 3d 20 . if (buf ==
0740: 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 75 72 6e 20 NULL) {..return
0750: 30 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 72 65 0;. }.. re
0760: 74 20 3d 20 54 63 6c 5f 52 65 61 64 52 61 77 28 t = Tcl_ReadRaw(
0770: 63 68 61 6e 2c 20 62 75 66 2c 20 28 54 63 6c 5f chan, buf, (Tcl_
0780: 53 69 7a 65 29 20 62 75 66 4c 65 6e 29 3b 0a 0a Size) bufLen);..
0790: 20 20 20 20 74 63 6c 45 6f 66 43 68 61 6e 20 3d tclEofChan =
07a0: 20 54 63 6c 5f 45 6f 66 28 63 68 61 6e 29 3b 0a Tcl_Eof(chan);.
07b0: 20 20 20 20 74 63 6c 45 72 72 6e 6f 20 3d 20 54 tclErrno = T
07c0: 63 6c 5f 47 65 74 45 72 72 6e 6f 28 29 3b 0a 0a cl_GetErrno();..
07d0: 20 20 20 20 64 70 72 69 6e 74 66 28 22 5b 63 68 dprintf("[ch
07e0: 61 6e 3d 25 70 5d 20 42 69 6f 52 65 61 64 28 25 an=%p] BioRead(%
07f0: 64 29 20 2d 3e 20 25 22 20 54 43 4c 5f 53 49 5a d) -> %" TCL_SIZ
0800: 45 5f 4d 4f 44 49 46 49 45 52 20 22 64 20 5b 74 E_MODIFIER "d [t
0810: 63 6c 45 6f 66 3d 25 64 3b 20 74 63 6c 45 72 72 clEof=%d; tclErr
0820: 6e 6f 3d 25 64 5d 22 2c 0a 09 28 76 6f 69 64 20 no=%d]",..(void
0830: 2a 29 20 63 68 61 6e 2c 20 62 75 66 4c 65 6e 2c *) chan, bufLen,
0840: 20 72 65 74 2c 20 74 63 6c 45 6f 66 43 68 61 6e ret, tclEofChan
0850: 2c 20 74 63 6c 45 72 72 6e 6f 29 3b 0a 0a 20 20 , tclErrno);..
0860: 20 20 42 49 4f 5f 63 6c 65 61 72 5f 66 6c 61 67 BIO_clear_flag
0870: 73 28 62 69 6f 2c 20 42 49 4f 5f 46 4c 41 47 53 s(bio, BIO_FLAGS
0880: 5f 52 45 41 44 20 7c 20 42 49 4f 5f 46 4c 41 47 _READ | BIO_FLAG
0890: 53 5f 53 48 4f 55 4c 44 5f 52 45 54 52 59 29 3b S_SHOULD_RETRY);
08a0: 0a 0a 20 20 20 20 69 66 20 28 74 63 6c 45 6f 66 .. if (tclEof
08b0: 43 68 61 6e 20 26 26 20 72 65 74 20 3c 3d 20 30 Chan && ret <= 0
08c0: 29 20 7b 0a 09 64 70 72 69 6e 74 66 28 22 47 6f ) {..dprintf("Go
08d0: 74 20 45 4f 46 20 77 68 69 6c 65 20 72 65 61 64 t EOF while read
08e0: 69 6e 67 2c 20 72 65 74 75 72 6e 69 6e 67 20 61 ing, returning a
08f0: 20 43 6f 6e 6e 65 63 74 69 6f 6e 20 52 65 73 65 Connection Rese
0900: 74 20 65 72 72 6f 72 20 77 68 69 63 68 20 6d 61 t error which ma
0910: 70 73 20 74 6f 20 53 6f 66 74 20 45 4f 46 22 29 ps to Soft EOF")
0920: 3b 0a 09 54 63 6c 5f 53 65 74 45 72 72 6e 6f 28 ;..Tcl_SetErrno(
0930: 45 43 4f 4e 4e 52 45 53 45 54 29 3b 0a 09 72 65 ECONNRESET);..re
0940: 74 20 3d 20 30 3b 0a 0a 20 20 20 20 7d 20 65 6c t = 0;.. } el
0950: 73 65 20 69 66 20 28 72 65 74 20 3d 3d 20 30 29 se if (ret == 0)
0960: 20 7b 0a 09 64 70 72 69 6e 74 66 28 22 47 6f 74 {..dprintf("Got
0970: 20 30 20 66 72 6f 6d 20 54 63 6c 5f 52 65 61 64 0 from Tcl_Read
0980: 20 6f 72 20 54 63 6c 5f 52 65 61 64 52 61 77 2c or Tcl_ReadRaw,
0990: 20 61 6e 64 20 45 4f 46 20 69 73 20 6e 6f 74 20 and EOF is not
09a0: 73 65 74 3b 20 72 65 74 20 3d 20 30 22 29 3b 0a set; ret = 0");.
09b0: 09 64 70 72 69 6e 74 66 28 22 53 65 74 74 69 6e .dprintf("Settin
09c0: 67 20 72 65 74 72 79 20 72 65 61 64 20 66 6c 61 g retry read fla
09d0: 67 22 29 3b 0a 09 42 49 4f 5f 73 65 74 5f 72 65 g");..BIO_set_re
09e0: 74 72 79 5f 72 65 61 64 28 62 69 6f 29 3b 0a 0a try_read(bio);..
09f0: 20 20 20 20 7d 20 65 6c 73 65 20 69 66 20 28 72 } else if (r
0a00: 65 74 20 3c 20 30 29 20 7b 0a 09 64 70 72 69 6e et < 0) {..dprin
0a10: 74 66 28 22 57 65 20 67 6f 74 20 73 6f 6d 65 20 tf("We got some
0a20: 6b 69 6e 64 20 6f 66 20 49 2f 4f 20 65 72 72 6f kind of I/O erro
0a30: 72 22 29 3b 0a 0a 09 69 66 20 28 74 63 6c 45 72 r");...if (tclEr
0a40: 72 6e 6f 20 3d 3d 20 45 41 47 41 49 4e 29 20 7b rno == EAGAIN) {
0a50: 0a 09 20 20 20 20 64 70 72 69 6e 74 66 28 22 49 .. dprintf("I
0a60: 74 27 73 20 45 41 47 41 49 4e 22 29 3b 0a 09 7d t's EAGAIN");..}
0a70: 20 65 6c 73 65 20 7b 0a 09 20 20 20 20 64 70 72 else {.. dpr
0a80: 69 6e 74 66 28 22 49 74 27 73 20 61 6e 20 75 6e intf("It's an un
0a90: 65 78 70 65 63 74 65 64 20 65 72 72 6f 72 3a 20 expected error:
0aa0: 25 73 2f 25 69 22 2c 20 54 63 6c 5f 45 72 72 6e %s/%i", Tcl_Errn
0ab0: 6f 4d 73 67 28 74 63 6c 45 72 72 6e 6f 29 2c 20 oMsg(tclErrno),
0ac0: 74 63 6c 45 72 72 6e 6f 29 3b 0a 09 7d 0a 0a 20 tclErrno);..}..
0ad0: 20 20 20 7d 20 65 6c 73 65 20 7b 0a 09 64 70 72 } else {..dpr
0ae0: 69 6e 74 66 28 22 53 75 63 63 65 73 73 66 75 6c intf("Successful
0af0: 6c 79 20 72 65 61 64 20 73 6f 6d 65 20 64 61 74 ly read some dat
0b00: 61 22 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 a");. }..
0b10: 69 66 20 28 72 65 74 20 21 3d 20 2d 31 20 7c 7c if (ret != -1 ||
0b20: 20 28 72 65 74 20 3d 3d 20 2d 31 20 26 26 20 74 (ret == -1 && t
0b30: 63 6c 45 72 72 6e 6f 20 3d 3d 20 45 41 47 41 49 clErrno == EAGAI
0b40: 4e 29 29 20 7b 0a 09 69 66 20 28 42 49 4f 5f 73 N)) {..if (BIO_s
0b50: 68 6f 75 6c 64 5f 77 72 69 74 65 28 62 69 6f 29 hould_write(bio)
0b60: 29 20 7b 0a 09 20 20 20 20 64 70 72 69 6e 74 66 ) {.. dprintf
0b70: 28 22 53 65 74 74 69 6e 67 20 73 68 6f 75 6c 64 ("Setting should
0b80: 20 72 65 74 72 79 20 77 72 69 74 65 20 66 6c 61 retry write fla
0b90: 67 22 29 3b 0a 0a 09 20 20 20 20 42 49 4f 5f 73 g");... BIO_s
0ba0: 65 74 5f 72 65 74 72 79 5f 77 72 69 74 65 28 62 et_retry_write(b
0bb0: 69 6f 29 3b 0a 09 7d 0a 20 20 20 20 7d 0a 0a 20 io);..}. }..
0bc0: 20 20 20 64 70 72 69 6e 74 66 28 22 42 69 6f 52 dprintf("BioR
0bd0: 65 61 64 28 25 70 2c 20 3c 62 75 66 3e 2c 20 25 ead(%p, <buf>, %
0be0: 64 29 20 5b 25 70 5d 20 72 65 74 75 72 6e 69 6e d) [%p] returnin
0bf0: 67 20 25 22 20 54 43 4c 5f 53 49 5a 45 5f 4d 4f g %" TCL_SIZE_MO
0c00: 44 49 46 49 45 52 20 22 64 22 2c 20 28 76 6f 69 DIFIER "d", (voi
0c10: 64 20 2a 29 20 62 69 6f 2c 0a 09 62 75 66 4c 65 d *) bio,..bufLe
0c20: 6e 2c 20 28 76 6f 69 64 20 2a 29 20 63 68 61 6e n, (void *) chan
0c30: 2c 20 72 65 74 29 3b 0a 0a 20 20 20 20 72 65 74 , ret);.. ret
0c40: 75 72 6e 28 28 69 6e 74 29 20 72 65 74 29 3b 0a urn((int) ret);.
0c50: 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 42 69 }..static int Bi
0c60: 6f 50 75 74 73 28 42 49 4f 20 2a 62 69 6f 2c 20 oPuts(BIO *bio,
0c70: 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 74 72 29 const char *str)
0c80: 20 7b 0a 20 20 20 20 64 70 72 69 6e 74 66 28 22 {. dprintf("
0c90: 42 69 6f 50 75 74 73 28 25 70 2c 20 3c 73 74 72 BioPuts(%p, <str
0ca0: 69 6e 67 3a 25 70 3e 29 20 63 61 6c 6c 65 64 22 ing:%p>) called"
0cb0: 2c 20 62 69 6f 2c 20 73 74 72 29 3b 0a 0a 20 20 , bio, str);..
0cc0: 20 20 72 65 74 75 72 6e 20 42 69 6f 57 72 69 74 return BioWrit
0cd0: 65 28 62 69 6f 2c 20 73 74 72 2c 20 28 69 6e 74 e(bio, str, (int
0ce0: 29 20 73 74 72 6c 65 6e 28 73 74 72 29 29 3b 0a ) strlen(str));.
0cf0: 7d 0a 0a 73 74 61 74 69 63 20 6c 6f 6e 67 20 42 }..static long B
0d00: 69 6f 43 74 72 6c 28 42 49 4f 20 2a 62 69 6f 2c ioCtrl(BIO *bio,
0d10: 20 69 6e 74 20 63 6d 64 2c 20 6c 6f 6e 67 20 6e int cmd, long n
0d20: 75 6d 2c 20 76 6f 69 64 20 2a 70 74 72 29 20 7b um, void *ptr) {
0d30: 0a 20 20 20 20 54 63 6c 5f 43 68 61 6e 6e 65 6c . Tcl_Channel
0d40: 20 63 68 61 6e 3b 0a 20 20 20 20 6c 6f 6e 67 20 chan;. long
0d50: 72 65 74 20 3d 20 31 3b 0a 0a 20 20 20 20 63 68 ret = 1;.. ch
0d60: 61 6e 20 3d 20 54 6c 73 5f 47 65 74 50 61 72 65 an = Tls_GetPare
0d70: 6e 74 28 28 53 74 61 74 65 20 2a 29 20 42 49 4f nt((State *) BIO
0d80: 5f 67 65 74 5f 64 61 74 61 28 62 69 6f 29 2c 20 _get_data(bio),
0d90: 30 29 3b 0a 0a 20 20 20 20 64 70 72 69 6e 74 66 0);.. dprintf
0da0: 28 22 42 69 6f 43 74 72 6c 28 25 70 2c 20 30 78 ("BioCtrl(%p, 0x
0db0: 25 78 2c 20 30 78 25 6c 78 2c 20 25 70 29 22 2c %x, 0x%lx, %p)",
0dc0: 20 28 76 6f 69 64 20 2a 29 20 62 69 6f 2c 20 63 (void *) bio, c
0dd0: 6d 64 2c 20 6e 75 6d 2c 20 70 74 72 29 3b 0a 0a md, num, ptr);..
0de0: 20 20 20 20 73 77 69 74 63 68 20 28 63 6d 64 29 switch (cmd)
0df0: 20 7b 0a 09 63 61 73 65 20 42 49 4f 5f 43 54 52 {..case BIO_CTR
0e00: 4c 5f 52 45 53 45 54 3a 0a 09 09 64 70 72 69 6e L_RESET:...dprin
0e10: 74 66 28 22 47 6f 74 20 42 49 4f 5f 43 54 52 4c tf("Got BIO_CTRL
0e20: 5f 52 45 53 45 54 22 29 3b 0a 09 09 6e 75 6d 20 _RESET");...num
0e30: 3d 20 30 3b 0a 09 09 72 65 74 20 3d 20 30 3b 0a = 0;...ret = 0;.
0e40: 09 09 62 72 65 61 6b 3b 0a 09 63 61 73 65 20 42 ..break;..case B
0e50: 49 4f 5f 43 5f 46 49 4c 45 5f 53 45 45 4b 3a 0a IO_C_FILE_SEEK:.
0e60: 09 09 64 70 72 69 6e 74 66 28 22 47 6f 74 20 42 ..dprintf("Got B
0e70: 49 4f 5f 43 5f 46 49 4c 45 5f 53 45 45 4b 22 29 IO_C_FILE_SEEK")
0e80: 3b 0a 09 09 72 65 74 20 3d 20 30 3b 0a 09 09 62 ;...ret = 0;...b
0e90: 72 65 61 6b 3b 0a 09 63 61 73 65 20 42 49 4f 5f reak;..case BIO_
0ea0: 43 5f 46 49 4c 45 5f 54 45 4c 4c 3a 0a 09 09 64 C_FILE_TELL:...d
0eb0: 70 72 69 6e 74 66 28 22 47 6f 74 20 42 49 4f 5f printf("Got BIO_
0ec0: 43 5f 46 49 4c 45 5f 54 45 4c 4c 22 29 3b 0a 09 C_FILE_TELL");..
0ed0: 09 72 65 74 20 3d 20 30 3b 0a 09 09 62 72 65 61 .ret = 0;...brea
0ee0: 6b 3b 0a 09 63 61 73 65 20 42 49 4f 5f 43 54 52 k;..case BIO_CTR
0ef0: 4c 5f 49 4e 46 4f 3a 0a 09 09 64 70 72 69 6e 74 L_INFO:...dprint
0f00: 66 28 22 47 6f 74 20 42 49 4f 5f 43 54 52 4c 5f f("Got BIO_CTRL_
0f10: 49 4e 46 4f 22 29 3b 0a 09 09 72 65 74 20 3d 20 INFO");...ret =
0f20: 31 3b 0a 09 09 62 72 65 61 6b 3b 0a 09 63 61 73 1;...break;..cas
0f30: 65 20 42 49 4f 5f 43 5f 53 45 54 5f 46 44 3a 0a e BIO_C_SET_FD:.
0f40: 09 09 64 70 72 69 6e 74 66 28 22 55 6e 73 75 70 ..dprintf("Unsup
0f50: 70 6f 72 74 65 64 20 63 61 6c 6c 3a 20 42 49 4f ported call: BIO
0f60: 5f 43 5f 53 45 54 5f 46 44 22 29 3b 0a 09 09 72 _C_SET_FD");...r
0f70: 65 74 20 3d 20 2d 31 3b 0a 09 09 62 72 65 61 6b et = -1;...break
0f80: 3b 0a 09 63 61 73 65 20 42 49 4f 5f 43 5f 47 45 ;..case BIO_C_GE
0f90: 54 5f 46 44 3a 0a 09 09 64 70 72 69 6e 74 66 28 T_FD:...dprintf(
0fa0: 22 55 6e 73 75 70 70 6f 72 74 65 64 20 63 61 6c "Unsupported cal
0fb0: 6c 3a 20 42 49 4f 5f 43 5f 47 45 54 5f 46 44 22 l: BIO_C_GET_FD"
0fc0: 29 3b 0a 09 09 72 65 74 20 3d 20 2d 31 3b 0a 09 );...ret = -1;..
0fd0: 09 62 72 65 61 6b 3b 0a 09 63 61 73 65 20 42 49 .break;..case BI
0fe0: 4f 5f 43 54 52 4c 5f 47 45 54 5f 43 4c 4f 53 45 O_CTRL_GET_CLOSE
0ff0: 3a 0a 09 09 64 70 72 69 6e 74 66 28 22 47 6f 74 :...dprintf("Got
1000: 20 42 49 4f 5f 43 54 52 4c 5f 43 4c 4f 53 45 22 BIO_CTRL_CLOSE"
1010: 29 3b 0a 09 09 72 65 74 20 3d 20 42 49 4f 5f 67 );...ret = BIO_g
1020: 65 74 5f 73 68 75 74 64 6f 77 6e 28 62 69 6f 29 et_shutdown(bio)
1030: 3b 0a 09 09 62 72 65 61 6b 3b 0a 09 63 61 73 65 ;...break;..case
1040: 20 42 49 4f 5f 43 54 52 4c 5f 53 45 54 5f 43 4c BIO_CTRL_SET_CL
1050: 4f 53 45 3a 0a 09 09 64 70 72 69 6e 74 66 28 22 OSE:...dprintf("
1060: 47 6f 74 20 42 49 4f 5f 53 45 54 5f 43 4c 4f 53 Got BIO_SET_CLOS
1070: 45 22 29 3b 0a 09 09 42 49 4f 5f 73 65 74 5f 73 E");...BIO_set_s
1080: 68 75 74 64 6f 77 6e 28 62 69 6f 2c 20 6e 75 6d hutdown(bio, num
1090: 29 3b 0a 09 09 62 72 65 61 6b 3b 0a 09 63 61 73 );...break;..cas
10a0: 65 20 42 49 4f 5f 43 54 52 4c 5f 45 4f 46 3a 0a e BIO_CTRL_EOF:.
10b0: 09 09 64 70 72 69 6e 74 66 28 22 47 6f 74 20 42 ..dprintf("Got B
10c0: 49 4f 5f 43 54 52 4c 5f 45 4f 46 22 29 3b 0a 09 IO_CTRL_EOF");..
10d0: 09 72 65 74 20 3d 20 28 28 63 68 61 6e 29 20 3f .ret = ((chan) ?
10e0: 20 54 63 6c 5f 45 6f 66 28 63 68 61 6e 29 20 3a Tcl_Eof(chan) :
10f0: 20 31 29 3b 0a 09 09 62 72 65 61 6b 3b 0a 09 63 1);...break;..c
1100: 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f 50 45 4e ase BIO_CTRL_PEN
1110: 44 49 4e 47 3a 0a 09 09 64 70 72 69 6e 74 66 28 DING:...dprintf(
1120: 22 47 6f 74 20 42 49 4f 5f 43 54 52 4c 5f 50 45 "Got BIO_CTRL_PE
1130: 4e 44 49 4e 47 22 29 3b 0a 09 09 72 65 74 20 3d NDING");...ret =
1140: 20 28 28 63 68 61 6e 29 20 3f 20 28 28 54 63 6c ((chan) ? ((Tcl
1150: 5f 49 6e 70 75 74 42 75 66 66 65 72 65 64 28 63 _InputBuffered(c
1160: 68 61 6e 29 20 3f 20 31 20 3a 20 30 29 29 20 3a han) ? 1 : 0)) :
1170: 20 30 29 3b 0a 09 09 64 70 72 69 6e 74 66 28 22 0);...dprintf("
1180: 42 49 4f 5f 43 54 52 4c 5f 50 45 4e 44 49 4e 47 BIO_CTRL_PENDING
1190: 28 25 64 29 22 2c 20 28 69 6e 74 29 20 72 65 74 (%d)", (int) ret
11a0: 29 3b 0a 09 09 62 72 65 61 6b 3b 0a 09 63 61 73 );...break;..cas
11b0: 65 20 42 49 4f 5f 43 54 52 4c 5f 57 50 45 4e 44 e BIO_CTRL_WPEND
11c0: 49 4e 47 3a 0a 09 09 64 70 72 69 6e 74 66 28 22 ING:...dprintf("
11d0: 47 6f 74 20 42 49 4f 5f 43 54 52 4c 5f 57 50 45 Got BIO_CTRL_WPE
11e0: 4e 44 49 4e 47 22 29 3b 0a 09 09 72 65 74 20 3d NDING");...ret =
11f0: 20 30 3b 0a 09 09 62 72 65 61 6b 3b 0a 09 63 61 0;...break;..ca
1200: 73 65 20 42 49 4f 5f 43 54 52 4c 5f 44 55 50 3a se BIO_CTRL_DUP:
1210: 0a 09 09 64 70 72 69 6e 74 66 28 22 47 6f 74 20 ...dprintf("Got
1220: 42 49 4f 5f 43 54 52 4c 5f 44 55 50 22 29 3b 0a BIO_CTRL_DUP");.
1230: 09 09 62 72 65 61 6b 3b 0a 09 63 61 73 65 20 42 ..break;..case B
1240: 49 4f 5f 43 54 52 4c 5f 46 4c 55 53 48 3a 0a 09 IO_CTRL_FLUSH:..
1250: 09 64 70 72 69 6e 74 66 28 22 47 6f 74 20 42 49 .dprintf("Got BI
1260: 4f 5f 43 54 52 4c 5f 46 4c 55 53 48 22 29 3b 0a O_CTRL_FLUSH");.
1270: 09 09 72 65 74 20 3d 20 28 28 63 68 61 6e 29 20 ..ret = ((chan)
1280: 26 26 20 28 54 63 6c 5f 57 72 69 74 65 52 61 77 && (Tcl_WriteRaw
1290: 28 63 68 61 6e 2c 20 22 22 2c 20 30 29 20 3e 3d (chan, "", 0) >=
12a0: 20 30 29 20 3f 20 31 20 3a 20 2d 31 29 3b 0a 09 0) ? 1 : -1);..
12b0: 09 64 70 72 69 6e 74 66 28 22 42 49 4f 5f 43 54 .dprintf("BIO_CT
12c0: 52 4c 5f 46 4c 55 53 48 20 72 65 74 75 72 6e 69 RL_FLUSH returni
12d0: 6e 67 20 76 61 6c 75 65 20 25 6c 69 22 2c 20 72 ng value %li", r
12e0: 65 74 29 3b 0a 09 09 62 72 65 61 6b 3b 0a 09 63 et);...break;..c
12f0: 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f 50 55 53 ase BIO_CTRL_PUS
1300: 48 3a 0a 09 09 64 70 72 69 6e 74 66 28 22 47 6f H:...dprintf("Go
1310: 74 20 42 49 4f 5f 43 54 52 4c 5f 50 55 53 48 22 t BIO_CTRL_PUSH"
1320: 29 3b 0a 09 09 72 65 74 20 3d 20 30 3b 0a 09 09 );...ret = 0;...
1330: 62 72 65 61 6b 3b 0a 09 63 61 73 65 20 42 49 4f break;..case BIO
1340: 5f 43 54 52 4c 5f 50 4f 50 3a 0a 09 09 64 70 72 _CTRL_POP:...dpr
1350: 69 6e 74 66 28 22 47 6f 74 20 42 49 4f 5f 43 54 intf("Got BIO_CT
1360: 52 4c 5f 50 4f 50 22 29 3b 0a 09 09 72 65 74 20 RL_POP");...ret
1370: 3d 20 30 3b 0a 09 09 62 72 65 61 6b 3b 0a 09 63 = 0;...break;..c
1380: 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f 53 45 54 ase BIO_CTRL_SET
1390: 3a 0a 09 09 64 70 72 69 6e 74 66 28 22 47 6f 74 :...dprintf("Got
13a0: 20 42 49 4f 5f 43 54 52 4c 5f 53 45 54 22 29 3b BIO_CTRL_SET");
13b0: 0a 09 09 72 65 74 20 3d 20 30 3b 0a 09 09 62 72 ...ret = 0;...br
13c0: 65 61 6b 3b 0a 09 63 61 73 65 20 42 49 4f 5f 43 eak;..case BIO_C
13d0: 54 52 4c 5f 47 45 54 20 3a 0a 09 09 64 70 72 69 TRL_GET :...dpri
13e0: 6e 74 66 28 22 47 6f 74 20 42 49 4f 5f 43 54 52 ntf("Got BIO_CTR
13f0: 4c 5f 47 45 54 20 22 29 3b 0a 09 09 72 65 74 20 L_GET ");...ret
1400: 3d 20 30 3b 0a 09 09 62 72 65 61 6b 3b 0a 23 69 = 0;...break;.#i
1410: 66 64 65 66 20 42 49 4f 5f 43 54 52 4c 5f 47 45 fdef BIO_CTRL_GE
1420: 54 5f 4b 54 4c 53 5f 53 45 4e 44 0a 09 63 61 73 T_KTLS_SEND..cas
1430: 65 20 42 49 4f 5f 43 54 52 4c 5f 47 45 54 5f 4b e BIO_CTRL_GET_K
1440: 54 4c 53 5f 53 45 4e 44 3a 0a 09 09 64 70 72 69 TLS_SEND:...dpri
1450: 6e 74 66 28 22 47 6f 74 20 42 49 4f 5f 43 54 52 ntf("Got BIO_CTR
1460: 4c 5f 47 45 54 5f 4b 54 4c 53 5f 53 45 4e 44 22 L_GET_KTLS_SEND"
1470: 29 3b 0a 09 09 72 65 74 20 3d 20 30 3b 0a 09 09 );...ret = 0;...
1480: 62 72 65 61 6b 3b 0a 23 65 6e 64 69 66 0a 23 69 break;.#endif.#i
1490: 66 64 65 66 20 42 49 4f 5f 43 54 52 4c 5f 47 45 fdef BIO_CTRL_GE
14a0: 54 5f 4b 54 4c 53 5f 52 45 43 56 0a 09 63 61 73 T_KTLS_RECV..cas
14b0: 65 20 42 49 4f 5f 43 54 52 4c 5f 47 45 54 5f 4b e BIO_CTRL_GET_K
14c0: 54 4c 53 5f 52 45 43 56 3a 0a 09 09 64 70 72 69 TLS_RECV:...dpri
14d0: 6e 74 66 28 22 47 6f 74 20 42 49 4f 5f 43 54 52 ntf("Got BIO_CTR
14e0: 4c 5f 47 45 54 5f 4b 54 4c 53 5f 52 45 43 56 22 L_GET_KTLS_RECV"
14f0: 29 3b 0a 09 09 72 65 74 20 3d 20 30 3b 0a 09 09 );...ret = 0;...
1500: 62 72 65 61 6b 3b 0a 23 65 6e 64 69 66 0a 09 64 break;.#endif..d
1510: 65 66 61 75 6c 74 3a 0a 09 09 64 70 72 69 6e 74 efault:...dprint
1520: 66 28 22 47 6f 74 20 75 6e 6b 6e 6f 77 6e 20 63 f("Got unknown c
1530: 6f 6e 74 72 6f 6c 20 63 6f 6d 6d 61 6e 64 20 28 ontrol command (
1540: 25 69 29 22 2c 20 63 6d 64 29 3b 0a 09 09 72 65 %i)", cmd);...re
1550: 74 20 3d 20 30 3b 0a 09 09 62 72 65 61 6b 3b 0a t = 0;...break;.
1560: 20 20 20 20 7d 0a 20 20 20 20 72 65 74 75 72 6e }. return
1570: 28 72 65 74 29 3b 0a 7d 0a 0a 73 74 61 74 69 63 (ret);.}..static
1580: 20 69 6e 74 20 42 69 6f 4e 65 77 28 42 49 4f 20 int BioNew(BIO
1590: 2a 62 69 6f 29 20 7b 0a 20 20 20 20 64 70 72 69 *bio) {. dpri
15a0: 6e 74 66 28 22 42 69 6f 4e 65 77 28 25 70 29 20 ntf("BioNew(%p)
15b0: 63 61 6c 6c 65 64 22 2c 20 62 69 6f 29 3b 0a 0a called", bio);..
15c0: 20 20 20 20 42 49 4f 5f 73 65 74 5f 69 6e 69 74 BIO_set_init
15d0: 28 62 69 6f 2c 20 30 29 3b 0a 20 20 20 20 42 49 (bio, 0);. BI
15e0: 4f 5f 73 65 74 5f 64 61 74 61 28 62 69 6f 2c 20 O_set_data(bio,
15f0: 4e 55 4c 4c 29 3b 0a 20 20 20 20 42 49 4f 5f 63 NULL);. BIO_c
1600: 6c 65 61 72 5f 66 6c 61 67 73 28 62 69 6f 2c 20 lear_flags(bio,
1610: 2d 31 29 3b 0a 20 20 20 20 72 65 74 75 72 6e 28 -1);. return(
1620: 31 29 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e 1);.}..static in
1630: 74 20 42 69 6f 46 72 65 65 28 42 49 4f 20 2a 62 t BioFree(BIO *b
1640: 69 6f 29 20 7b 0a 20 20 20 20 69 66 20 28 62 69 io) {. if (bi
1650: 6f 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 72 65 o == NULL) {..re
1660: 74 75 72 6e 28 30 29 3b 0a 20 20 20 20 7d 0a 0a turn(0);. }..
1670: 20 20 20 20 64 70 72 69 6e 74 66 28 22 42 69 6f dprintf("Bio
1680: 46 72 65 65 28 25 70 29 20 63 61 6c 6c 65 64 22 Free(%p) called"
1690: 2c 20 62 69 6f 29 3b 0a 0a 20 20 20 20 69 66 20 , bio);.. if
16a0: 28 42 49 4f 5f 67 65 74 5f 73 68 75 74 64 6f 77 (BIO_get_shutdow
16b0: 6e 28 62 69 6f 29 29 20 7b 0a 09 69 66 20 28 42 n(bio)) {..if (B
16c0: 49 4f 5f 67 65 74 5f 69 6e 69 74 28 62 69 6f 29 IO_get_init(bio)
16d0: 29 20 7b 0a 09 20 20 20 20 2f 2a 73 68 75 74 64 ) {.. /*shutd
16e0: 6f 77 6e 28 62 69 6f 2d 3e 6e 75 6d 2c 20 32 29 own(bio->num, 2)
16f0: 20 2a 2f 0a 09 20 20 20 20 2f 2a 63 6c 6f 73 65 */.. /*close
1700: 73 6f 63 6b 65 74 28 62 69 6f 2d 3e 6e 75 6d 29 socket(bio->num)
1710: 20 2a 2f 0a 09 7d 0a 0a 09 42 49 4f 5f 73 65 74 */..}...BIO_set
1720: 5f 69 6e 69 74 28 62 69 6f 2c 20 30 29 3b 0a 09 _init(bio, 0);..
1730: 42 49 4f 5f 63 6c 65 61 72 5f 66 6c 61 67 73 28 BIO_clear_flags(
1740: 62 69 6f 2c 20 2d 31 29 3b 0a 20 20 20 20 7d 0a bio, -1);. }.
1750: 20 20 20 20 72 65 74 75 72 6e 28 31 29 3b 0a 7d return(1);.}
1760: 0a 0a 42 49 4f 20 2a 42 49 4f 5f 6e 65 77 5f 74 ..BIO *BIO_new_t
1770: 63 6c 28 53 74 61 74 65 20 2a 73 74 61 74 65 50 cl(State *stateP
1780: 74 72 2c 20 69 6e 74 20 66 6c 61 67 73 29 20 7b tr, int flags) {
1790: 0a 20 20 20 20 42 49 4f 20 2a 62 69 6f 3b 0a 20 . BIO *bio;.
17a0: 20 20 20 73 74 61 74 69 63 20 42 49 4f 5f 4d 45 static BIO_ME
17b0: 54 48 4f 44 20 2a 42 69 6f 4d 65 74 68 6f 64 73 THOD *BioMethods
17c0: 20 3d 20 4e 55 4c 4c 3b 0a 23 69 66 64 65 66 20 = NULL;.#ifdef
17d0: 54 43 4c 54 4c 53 5f 53 53 4c 5f 55 53 45 5f 46 TCLTLS_SSL_USE_F
17e0: 41 53 54 50 41 54 48 0a 20 20 20 20 54 63 6c 5f ASTPATH. Tcl_
17f0: 43 68 61 6e 6e 65 6c 20 70 61 72 65 6e 74 43 68 Channel parentCh
1800: 61 6e 6e 65 6c 3b 0a 20 20 20 20 63 6f 6e 73 74 annel;. const
1810: 20 54 63 6c 5f 43 68 61 6e 6e 65 6c 54 79 70 65 Tcl_ChannelType
1820: 20 2a 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c 54 *parentChannelT
1830: 79 70 65 3b 0a 20 20 20 20 76 6f 69 64 20 2a 70 ype;. void *p
1840: 61 72 65 6e 74 43 68 61 6e 6e 65 6c 46 64 49 6e arentChannelFdIn
1850: 5f 70 2c 20 2a 70 61 72 65 6e 74 43 68 61 6e 6e _p, *parentChann
1860: 65 6c 46 64 4f 75 74 5f 70 3b 0a 20 20 20 20 69 elFdOut_p;. i
1870: 6e 74 20 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c nt parentChannel
1880: 46 64 49 6e 2c 20 70 61 72 65 6e 74 43 68 61 6e FdIn, parentChan
1890: 6e 65 6c 46 64 4f 75 74 2c 20 70 61 72 65 6e 74 nelFdOut, parent
18a0: 43 68 61 6e 6e 65 6c 46 64 3b 0a 20 20 20 20 69 ChannelFd;. i
18b0: 6e 74 20 76 61 6c 69 64 50 61 72 65 6e 74 43 68 nt validParentCh
18c0: 61 6e 6e 65 6c 46 64 3b 0a 20 20 20 20 69 6e 74 annelFd;. int
18d0: 20 74 63 6c 47 65 74 43 68 61 6e 6e 65 6c 48 61 tclGetChannelHa
18e0: 6e 64 6c 65 52 65 74 3b 0a 23 65 6e 64 69 66 0a ndleRet;.#endif.
18f0: 0a 20 20 20 20 64 70 72 69 6e 74 66 28 22 42 49 . dprintf("BI
1900: 4f 5f 6e 65 77 5f 74 63 6c 28 29 20 63 61 6c 6c O_new_tcl() call
1910: 65 64 22 29 3b 0a 0a 20 20 20 20 69 66 20 28 42 ed");.. if (B
1920: 69 6f 4d 65 74 68 6f 64 73 20 3d 3d 20 4e 55 4c ioMethods == NUL
1930: 4c 29 20 7b 0a 09 42 69 6f 4d 65 74 68 6f 64 73 L) {..BioMethods
1940: 20 3d 20 42 49 4f 5f 6d 65 74 68 5f 6e 65 77 28 = BIO_meth_new(
1950: 42 49 4f 5f 54 59 50 45 5f 54 43 4c 2c 20 22 74 BIO_TYPE_TCL, "t
1960: 63 6c 22 29 3b 0a 09 42 49 4f 5f 6d 65 74 68 5f cl");..BIO_meth_
1970: 73 65 74 5f 77 72 69 74 65 28 42 69 6f 4d 65 74 set_write(BioMet
1980: 68 6f 64 73 2c 20 42 69 6f 57 72 69 74 65 29 3b hods, BioWrite);
1990: 0a 09 42 49 4f 5f 6d 65 74 68 5f 73 65 74 5f 72 ..BIO_meth_set_r
19a0: 65 61 64 28 42 69 6f 4d 65 74 68 6f 64 73 2c 20 ead(BioMethods,
19b0: 42 69 6f 52 65 61 64 29 3b 0a 09 42 49 4f 5f 6d BioRead);..BIO_m
19c0: 65 74 68 5f 73 65 74 5f 70 75 74 73 28 42 69 6f eth_set_puts(Bio
19d0: 4d 65 74 68 6f 64 73 2c 20 42 69 6f 50 75 74 73 Methods, BioPuts
19e0: 29 3b 0a 09 42 49 4f 5f 6d 65 74 68 5f 73 65 74 );..BIO_meth_set
19f0: 5f 63 74 72 6c 28 42 69 6f 4d 65 74 68 6f 64 73 _ctrl(BioMethods
1a00: 2c 20 42 69 6f 43 74 72 6c 29 3b 0a 09 42 49 4f , BioCtrl);..BIO
1a10: 5f 6d 65 74 68 5f 73 65 74 5f 63 72 65 61 74 65 _meth_set_create
1a20: 28 42 69 6f 4d 65 74 68 6f 64 73 2c 20 42 69 6f (BioMethods, Bio
1a30: 4e 65 77 29 3b 0a 09 42 49 4f 5f 6d 65 74 68 5f New);..BIO_meth_
1a40: 73 65 74 5f 64 65 73 74 72 6f 79 28 42 69 6f 4d set_destroy(BioM
1a50: 65 74 68 6f 64 73 2c 20 42 69 6f 46 72 65 65 29 ethods, BioFree)
1a60: 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 69 66 20 ;. }.. if
1a70: 28 73 74 61 74 65 50 74 72 20 3d 3d 20 4e 55 4c (statePtr == NUL
1a80: 4c 29 20 7b 0a 09 64 70 72 69 6e 74 66 28 22 41 L) {..dprintf("A
1a90: 73 6b 65 64 20 74 6f 20 73 65 74 75 70 20 61 20 sked to setup a
1aa0: 4e 55 4c 4c 20 73 74 61 74 65 2c 20 6a 75 73 74 NULL state, just
1ab0: 20 63 72 65 61 74 69 6e 67 20 74 68 65 20 69 6e creating the in
1ac0: 69 74 69 61 6c 20 63 6f 6e 66 69 67 75 72 61 74 itial configurat
1ad0: 69 6f 6e 22 29 3b 0a 0a 09 72 65 74 75 72 6e 28 ion");...return(
1ae0: 4e 55 4c 4c 29 3b 0a 20 20 20 20 7d 0a 0a 23 69 NULL);. }..#i
1af0: 66 64 65 66 20 54 43 4c 54 4c 53 5f 53 53 4c 5f fdef TCLTLS_SSL_
1b00: 55 53 45 5f 46 41 53 54 50 41 54 48 0a 20 20 20 USE_FASTPATH.
1b10: 20 2f 2a 0a 20 20 20 20 20 2a 20 49 66 20 74 68 /*. * If th
1b20: 65 20 63 68 61 6e 6e 65 6c 20 63 61 6e 20 62 65 e channel can be
1b30: 20 6d 61 70 70 65 64 20 62 61 63 6b 20 74 6f 20 mapped back to
1b40: 61 20 66 69 6c 65 20 64 65 73 63 72 69 70 74 6f a file descripto
1b50: 72 2c 20 6a 75 73 74 20 75 73 65 20 74 68 65 20 r, just use the
1b60: 66 69 6c 65 20 64 65 73 63 72 69 70 74 6f 72 0a file descriptor.
1b70: 20 20 20 20 20 2a 20 77 69 74 68 20 74 68 65 20 * with the
1b80: 53 53 4c 20 6c 69 62 72 61 72 79 20 73 69 6e 63 SSL library sinc
1b90: 65 20 69 74 20 77 69 6c 6c 20 6c 69 6b 65 6c 79 e it will likely
1ba0: 20 62 65 20 6f 70 74 69 6d 69 7a 65 64 20 66 6f be optimized fo
1bb0: 72 20 74 68 69 73 2e 0a 20 20 20 20 20 2a 2f 0a r this.. */.
1bc0: 20 20 20 20 70 61 72 65 6e 74 43 68 61 6e 6e 65 parentChanne
1bd0: 6c 20 3d 20 54 6c 73 5f 47 65 74 50 61 72 65 6e l = Tls_GetParen
1be0: 74 28 73 74 61 74 65 50 74 72 2c 20 30 29 3b 0a t(statePtr, 0);.
1bf0: 20 20 20 20 70 61 72 65 6e 74 43 68 61 6e 6e 65 parentChanne
1c00: 6c 54 79 70 65 20 3d 20 54 63 6c 5f 47 65 74 43 lType = Tcl_GetC
1c10: 68 61 6e 6e 65 6c 54 79 70 65 28 70 61 72 65 6e hannelType(paren
1c20: 74 43 68 61 6e 6e 65 6c 29 3b 0a 0a 20 20 20 20 tChannel);..
1c30: 76 61 6c 69 64 50 61 72 65 6e 74 43 68 61 6e 6e validParentChann
1c40: 65 6c 46 64 20 3d 20 30 3b 0a 20 20 20 20 69 66 elFd = 0;. if
1c50: 20 28 73 74 72 63 6d 70 28 70 61 72 65 6e 74 43 (strcmp(parentC
1c60: 68 61 6e 6e 65 6c 54 79 70 65 2d 3e 74 79 70 65 hannelType->type
1c70: 4e 61 6d 65 2c 20 22 74 63 70 22 29 20 3d 3d 20 Name, "tcp") ==
1c80: 30 29 20 7b 0a 09 74 63 6c 47 65 74 43 68 61 6e 0) {..tclGetChan
1c90: 6e 65 6c 48 61 6e 64 6c 65 52 65 74 20 3d 20 54 nelHandleRet = T
1ca0: 63 6c 5f 47 65 74 43 68 61 6e 6e 65 6c 48 61 6e cl_GetChannelHan
1cb0: 64 6c 65 28 70 61 72 65 6e 74 43 68 61 6e 6e 65 dle(parentChanne
1cc0: 6c 2c 20 54 43 4c 5f 52 45 41 44 41 42 4c 45 2c l, TCL_READABLE,
1cd0: 20 28 43 6c 69 65 6e 74 44 61 74 61 29 20 26 70 (ClientData) &p
1ce0: 61 72 65 6e 74 43 68 61 6e 6e 65 6c 46 64 49 6e arentChannelFdIn
1cf0: 5f 70 29 3b 0a 09 69 66 20 28 74 63 6c 47 65 74 _p);..if (tclGet
1d00: 43 68 61 6e 6e 65 6c 48 61 6e 64 6c 65 52 65 74 ChannelHandleRet
1d10: 20 3d 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 20 == TCL_OK) {..
1d20: 20 20 20 74 63 6c 47 65 74 43 68 61 6e 6e 65 6c tclGetChannel
1d30: 48 61 6e 64 6c 65 52 65 74 20 3d 20 54 63 6c 5f HandleRet = Tcl_
1d40: 47 65 74 43 68 61 6e 6e 65 6c 48 61 6e 64 6c 65 GetChannelHandle
1d50: 28 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c 2c 20 (parentChannel,
1d60: 54 43 4c 5f 57 52 49 54 41 42 4c 45 2c 20 28 43 TCL_WRITABLE, (C
1d70: 6c 69 65 6e 74 44 61 74 61 29 20 26 70 61 72 65 lientData) &pare
1d80: 6e 74 43 68 61 6e 6e 65 6c 46 64 4f 75 74 5f 70 ntChannelFdOut_p
1d90: 29 3b 0a 09 20 20 20 20 69 66 20 28 74 63 6c 47 );.. if (tclG
1da0: 65 74 43 68 61 6e 6e 65 6c 48 61 6e 64 6c 65 52 etChannelHandleR
1db0: 65 74 20 3d 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a et == TCL_OK) {.
1dc0: 09 09 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c 46 ..parentChannelF
1dd0: 64 49 6e 20 3d 20 50 54 52 32 49 4e 54 28 70 61 dIn = PTR2INT(pa
1de0: 72 65 6e 74 43 68 61 6e 6e 65 6c 46 64 49 6e 5f rentChannelFdIn_
1df0: 70 29 3b 0a 09 09 70 61 72 65 6e 74 43 68 61 6e p);...parentChan
1e00: 6e 65 6c 46 64 4f 75 74 20 3d 20 50 54 52 32 49 nelFdOut = PTR2I
1e10: 4e 54 28 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c NT(parentChannel
1e20: 46 64 4f 75 74 5f 70 29 3b 0a 09 09 69 66 20 28 FdOut_p);...if (
1e30: 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c 46 64 49 parentChannelFdI
1e40: 6e 20 3d 3d 20 70 61 72 65 6e 74 43 68 61 6e 6e n == parentChann
1e50: 65 6c 46 64 4f 75 74 29 20 7b 0a 09 09 20 20 20 elFdOut) {...
1e60: 20 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c 46 64 parentChannelFd
1e70: 20 3d 20 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c = parentChannel
1e80: 46 64 49 6e 3b 0a 09 09 20 20 20 20 76 61 6c 69 FdIn;... vali
1e90: 64 50 61 72 65 6e 74 43 68 61 6e 6e 65 6c 46 64 dParentChannelFd
1ea0: 20 3d 20 31 3b 0a 09 09 7d 0a 09 20 20 20 20 7d = 1;...}.. }
1eb0: 0a 09 7d 0a 20 20 20 20 7d 0a 0a 20 20 20 20 69 ..}. }.. i
1ec0: 66 20 28 76 61 6c 69 64 50 61 72 65 6e 74 43 68 f (validParentCh
1ed0: 61 6e 6e 65 6c 46 64 29 20 7b 0a 09 64 70 72 69 annelFd) {..dpri
1ee0: 6e 74 66 28 22 57 65 20 66 6f 75 6e 64 20 61 20 ntf("We found a
1ef0: 73 68 6f 72 74 63 75 74 2c 20 74 68 69 73 20 63 shortcut, this c
1f00: 68 61 6e 6e 65 6c 20 69 73 20 62 61 63 6b 65 64 hannel is backed
1f10: 20 62 79 20 61 20 73 6f 63 6b 65 74 3a 20 25 69 by a socket: %i
1f20: 22 2c 20 70 61 72 65 6e 74 43 68 61 6e 6e 65 6c ", parentChannel
1f30: 46 64 49 6e 29 3b 0a 09 62 69 6f 20 3d 20 42 49 FdIn);..bio = BI
1f40: 4f 5f 6e 65 77 5f 73 6f 63 6b 65 74 28 70 61 72 O_new_socket(par
1f50: 65 6e 74 43 68 61 6e 6e 65 6c 46 64 2c 20 66 6c entChannelFd, fl
1f60: 61 67 73 29 3b 0a 09 73 74 61 74 65 50 74 72 2d ags);..statePtr-
1f70: 3e 66 6c 61 67 73 20 7c 3d 20 54 4c 53 5f 54 43 >flags |= TLS_TC
1f80: 4c 5f 46 41 53 54 50 41 54 48 3b 0a 09 72 65 74 L_FASTPATH;..ret
1f90: 75 72 6e 28 62 69 6f 29 3b 0a 20 20 20 20 7d 0a urn(bio);. }.
1fa0: 0a 20 20 20 20 64 70 72 69 6e 74 66 28 22 46 61 . dprintf("Fa
1fb0: 6c 6c 69 6e 67 20 62 61 63 6b 20 74 6f 20 54 63 lling back to Tc
1fc0: 6c 20 49 2f 4f 20 66 6f 72 20 74 68 69 73 20 63 l I/O for this c
1fd0: 68 61 6e 6e 65 6c 22 29 3b 0a 23 65 6e 64 69 66 hannel");.#endif
1fe0: 0a 0a 20 20 20 20 62 69 6f 20 3d 20 42 49 4f 5f .. bio = BIO_
1ff0: 6e 65 77 28 42 69 6f 4d 65 74 68 6f 64 73 29 3b new(BioMethods);
2000: 0a 20 20 20 20 42 49 4f 5f 73 65 74 5f 64 61 74 . BIO_set_dat
2010: 61 28 62 69 6f 2c 20 73 74 61 74 65 50 74 72 29 a(bio, statePtr)
2020: 3b 0a 20 20 20 20 42 49 4f 5f 73 65 74 5f 73 68 ;. BIO_set_sh
2030: 75 74 64 6f 77 6e 28 62 69 6f 2c 20 66 6c 61 67 utdown(bio, flag
2040: 73 29 3b 0a 20 20 20 20 42 49 4f 5f 73 65 74 5f s);. BIO_set_
2050: 69 6e 69 74 28 62 69 6f 2c 20 31 29 3b 0a 20 20 init(bio, 1);.
2060: 20 20 72 65 74 75 72 6e 28 62 69 6f 29 3b 0a 7d return(bio);.}
2070: 0a .