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 24 48 65 61 64 65 72 3a 20 2f 68 6f . * $Header: /ho
0050: 6d 65 2f 72 6b 65 65 6e 65 2f 74 6d 70 2f 63 76 me/rkeene/tmp/cv
0060: 73 32 66 6f 73 73 69 6c 2f 2e 2e 2f 74 63 6c 74 s2fossil/../tclt
0070: 6c 73 2f 74 6c 73 2f 74 6c 73 2f 74 6c 73 42 49 ls/tls/tls/tlsBI
0080: 4f 2e 63 2c 76 20 31 2e 33 20 32 30 30 30 2f 30 O.c,v 1.3 2000/0
0090: 37 2f 32 37 20 30 31 3a 35 38 3a 31 38 20 68 6f 7/27 01:58:18 ho
00a0: 62 62 73 20 45 78 70 20 24 0a 20 2a 0a 20 2a 20 bbs Exp $. *. *
00b0: 50 72 6f 76 69 64 65 73 20 42 49 4f 20 6c 61 79 Provides BIO lay
00c0: 65 72 20 74 6f 20 69 6e 74 65 72 66 61 63 65 20 er to interface
00d0: 6f 70 65 6e 73 73 6c 20 74 6f 20 54 63 6c 2e 0a openssl to Tcl..
00e0: 20 2a 2f 0a 0a 23 69 6e 63 6c 75 64 65 20 22 74 */..#include "t
00f0: 6c 73 49 6e 74 2e 68 22 0a 0a 2f 2a 0a 20 2a 20 lsInt.h"../*. *
0100: 46 6f 72 77 61 72 64 20 64 65 63 6c 61 72 61 74 Forward declarat
0110: 69 6f 6e 73 0a 20 2a 2f 0a 0a 73 74 61 74 69 63 ions. */..static
0120: 20 69 6e 74 20 42 69 6f 57 72 69 74 65 09 5f 41 int BioWrite._A
0130: 4e 53 49 5f 41 52 47 53 5f 20 28 28 42 49 4f 20 NSI_ARGS_ ((BIO
0140: 2a 68 2c 20 63 68 61 72 20 2a 62 75 66 2c 20 69 *h, char *buf, i
0150: 6e 74 20 6e 75 6d 29 29 3b 0a 73 74 61 74 69 63 nt num));.static
0160: 20 69 6e 74 20 42 69 6f 52 65 61 64 09 5f 41 4e int BioRead._AN
0170: 53 49 5f 41 52 47 53 5f 20 28 28 42 49 4f 20 2a SI_ARGS_ ((BIO *
0180: 68 2c 20 63 68 61 72 20 2a 62 75 66 2c 20 69 6e h, char *buf, in
0190: 74 20 6e 75 6d 29 29 3b 0a 73 74 61 74 69 63 20 t num));.static
01a0: 69 6e 74 20 42 69 6f 50 75 74 73 09 5f 41 4e 53 int BioPuts._ANS
01b0: 49 5f 41 52 47 53 5f 20 28 28 42 49 4f 20 2a 68 I_ARGS_ ((BIO *h
01c0: 2c 20 63 68 61 72 20 2a 73 74 72 29 29 3b 0a 73 , char *str));.s
01d0: 74 61 74 69 63 20 6c 6f 6e 67 20 42 69 6f 43 74 tatic long BioCt
01e0: 72 6c 09 5f 41 4e 53 49 5f 41 52 47 53 5f 20 28 rl._ANSI_ARGS_ (
01f0: 28 42 49 4f 20 2a 68 2c 20 69 6e 74 20 63 6d 64 (BIO *h, int cmd
0200: 2c 20 6c 6f 6e 67 20 61 72 67 31 2c 20 63 68 61 , long arg1, cha
0210: 72 20 2a 70 74 72 29 29 3b 0a 73 74 61 74 69 63 r *ptr));.static
0220: 20 69 6e 74 20 42 69 6f 4e 65 77 09 5f 41 4e 53 int BioNew._ANS
0230: 49 5f 41 52 47 53 5f 20 28 28 42 49 4f 20 2a 68 I_ARGS_ ((BIO *h
0240: 29 29 3b 0a 73 74 61 74 69 63 20 69 6e 74 20 42 ));.static int B
0250: 69 6f 46 72 65 65 09 5f 41 4e 53 49 5f 41 52 47 ioFree._ANSI_ARG
0260: 53 5f 20 28 28 42 49 4f 20 2a 68 29 29 3b 0a 0a S_ ((BIO *h));..
0270: 0a 73 74 61 74 69 63 20 42 49 4f 5f 4d 45 54 48 .static BIO_METH
0280: 4f 44 20 42 69 6f 4d 65 74 68 6f 64 73 20 3d 20 OD BioMethods =
0290: 7b 0a 20 20 20 20 42 49 4f 5f 54 59 50 45 5f 54 {. BIO_TYPE_T
02a0: 43 4c 2c 20 22 74 63 6c 22 2c 0a 20 20 20 20 42 CL, "tcl",. B
02b0: 69 6f 57 72 69 74 65 2c 0a 20 20 20 20 42 69 6f ioWrite,. Bio
02c0: 52 65 61 64 2c 0a 20 20 20 20 42 69 6f 50 75 74 Read,. BioPut
02d0: 73 2c 0a 20 20 20 20 4e 55 4c 4c 2c 09 2f 2a 20 s,. NULL,./*
02e0: 42 69 6f 47 65 74 73 20 2a 2f 0a 20 20 20 20 42 BioGets */. B
02f0: 69 6f 43 74 72 6c 2c 0a 20 20 20 20 42 69 6f 4e ioCtrl,. BioN
0300: 65 77 2c 0a 20 20 20 20 42 69 6f 46 72 65 65 2c ew,. BioFree,
0310: 0a 7d 3b 0a 0a 42 49 4f 20 2a 0a 42 49 4f 5f 6e .};..BIO *.BIO_n
0320: 65 77 5f 74 63 6c 28 73 74 61 74 65 50 74 72 2c ew_tcl(statePtr,
0330: 20 66 6c 61 67 73 29 0a 20 20 20 20 53 74 61 74 flags). Stat
0340: 65 20 2a 73 74 61 74 65 50 74 72 3b 0a 20 20 20 e *statePtr;.
0350: 20 69 6e 74 20 66 6c 61 67 73 3b 0a 7b 0a 20 20 int flags;.{.
0360: 20 20 42 49 4f 20 2a 62 69 6f 3b 0a 0a 20 20 20 BIO *bio;..
0370: 20 62 69 6f 09 09 09 3d 20 42 49 4f 5f 6e 65 77 bio...= BIO_new
0380: 28 26 42 69 6f 4d 65 74 68 6f 64 73 29 3b 0a 20 (&BioMethods);.
0390: 20 20 20 62 69 6f 2d 3e 70 74 72 09 09 3d 20 28 bio->ptr..= (
03a0: 63 68 61 72 2a 29 73 74 61 74 65 50 74 72 3b 0a char*)statePtr;.
03b0: 20 20 20 20 62 69 6f 2d 3e 69 6e 69 74 09 09 3d bio->init..=
03c0: 20 31 3b 0a 20 20 20 20 62 69 6f 2d 3e 73 68 75 1;. bio->shu
03d0: 74 64 6f 77 6e 09 3d 20 66 6c 61 67 73 3b 0a 0a tdown.= flags;..
03e0: 20 20 20 20 72 65 74 75 72 6e 20 62 69 6f 3b 0a return bio;.
03f0: 7d 0a 0a 42 49 4f 5f 4d 45 54 48 4f 44 20 2a 0a }..BIO_METHOD *.
0400: 42 49 4f 5f 73 5f 74 63 6c 28 29 0a 7b 0a 20 20 BIO_s_tcl().{.
0410: 20 20 72 65 74 75 72 6e 20 26 42 69 6f 4d 65 74 return &BioMet
0420: 68 6f 64 73 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 hods;.}..static
0430: 69 6e 74 0a 42 69 6f 57 72 69 74 65 20 28 62 69 int.BioWrite (bi
0440: 6f 2c 20 62 75 66 2c 20 62 75 66 4c 65 6e 29 0a o, buf, bufLen).
0450: 20 20 20 20 42 49 4f 20 2a 62 69 6f 3b 0a 20 20 BIO *bio;.
0460: 20 20 63 68 61 72 20 2a 62 75 66 3b 0a 20 20 20 char *buf;.
0470: 20 69 6e 74 20 62 75 66 4c 65 6e 3b 0a 7b 0a 20 int bufLen;.{.
0480: 20 20 20 54 63 6c 5f 43 68 61 6e 6e 65 6c 20 63 Tcl_Channel c
0490: 68 61 6e 20 3d 20 54 6c 73 5f 47 65 74 50 61 72 han = Tls_GetPar
04a0: 65 6e 74 28 28 53 74 61 74 65 2a 29 28 62 69 6f ent((State*)(bio
04b0: 2d 3e 70 74 72 29 29 3b 0a 20 20 20 20 69 6e 74 ->ptr));. int
04c0: 20 72 65 74 3b 0a 0a 20 20 20 20 64 70 72 69 6e ret;.. dprin
04d0: 74 66 28 73 74 64 65 72 72 2c 22 5c 6e 42 69 6f tf(stderr,"\nBio
04e0: 57 72 69 74 65 28 30 78 25 78 2c 20 3c 62 75 66 Write(0x%x, <buf
04f0: 3e 2c 20 25 64 29 20 5b 30 78 25 78 5d 22 2c 20 >, %d) [0x%x]",
0500: 62 69 6f 2c 20 62 75 66 4c 65 6e 2c 20 63 68 61 bio, bufLen, cha
0510: 6e 29 3b 0a 0a 23 69 66 64 65 66 20 54 43 4c 5f n);..#ifdef TCL_
0520: 43 48 41 4e 4e 45 4c 5f 56 45 52 53 49 4f 4e 5f CHANNEL_VERSION_
0530: 32 0a 20 20 20 20 72 65 74 20 3d 20 54 63 6c 5f 2. ret = Tcl_
0540: 57 72 69 74 65 52 61 77 28 63 68 61 6e 2c 20 62 WriteRaw(chan, b
0550: 75 66 2c 20 62 75 66 4c 65 6e 29 3b 0a 23 65 6c uf, bufLen);.#el
0560: 73 65 0a 20 20 20 20 72 65 74 20 3d 20 54 63 6c se. ret = Tcl
0570: 5f 57 72 69 74 65 28 63 68 61 6e 2c 20 62 75 66 _Write(chan, buf
0580: 2c 20 62 75 66 4c 65 6e 29 3b 0a 23 65 6e 64 69 , bufLen);.#endi
0590: 66 0a 0a 20 20 20 20 64 70 72 69 6e 74 66 28 73 f.. dprintf(s
05a0: 74 64 65 72 72 2c 22 5c 6e 5b 30 78 25 78 5d 20 tderr,"\n[0x%x]
05b0: 42 69 6f 57 72 69 74 65 28 25 64 29 20 2d 3e 20 BioWrite(%d) ->
05c0: 25 64 20 5b 25 64 2e 25 64 5d 22 2c 20 63 68 61 %d [%d.%d]", cha
05d0: 6e 2c 20 62 75 66 4c 65 6e 2c 20 72 65 74 2c 0a n, bufLen, ret,.
05e0: 09 20 20 20 20 54 63 6c 5f 45 6f 66 28 63 68 61 . Tcl_Eof(cha
05f0: 6e 29 2c 20 54 63 6c 5f 47 65 74 45 72 72 6e 6f n), Tcl_GetErrno
0600: 28 29 29 3b 0a 0a 20 20 20 20 42 49 4f 5f 63 6c ());.. BIO_cl
0610: 65 61 72 5f 66 6c 61 67 73 28 62 69 6f 2c 20 42 ear_flags(bio, B
0620: 49 4f 5f 46 4c 41 47 53 5f 57 52 49 54 45 7c 42 IO_FLAGS_WRITE|B
0630: 49 4f 5f 46 4c 41 47 53 5f 53 48 4f 55 4c 44 5f IO_FLAGS_SHOULD_
0640: 52 45 54 52 59 29 3b 0a 0a 20 20 20 20 69 66 20 RETRY);.. if
0650: 28 72 65 74 20 3d 3d 20 30 29 20 7b 0a 09 69 66 (ret == 0) {..if
0660: 20 28 21 54 63 6c 5f 45 6f 66 28 63 68 61 6e 29 (!Tcl_Eof(chan)
0670: 29 20 7b 0a 09 20 20 20 20 42 49 4f 5f 73 65 74 ) {.. BIO_set
0680: 5f 72 65 74 72 79 5f 77 72 69 74 65 28 62 69 6f _retry_write(bio
0690: 29 3b 0a 09 20 20 20 20 72 65 74 20 3d 20 2d 31 );.. ret = -1
06a0: 3b 0a 09 7d 0a 20 20 20 20 7d 0a 20 20 20 20 69 ;..}. }. i
06b0: 66 20 28 42 49 4f 5f 73 68 6f 75 6c 64 5f 72 65 f (BIO_should_re
06c0: 61 64 28 62 69 6f 29 29 20 7b 0a 09 42 49 4f 5f ad(bio)) {..BIO_
06d0: 73 65 74 5f 72 65 74 72 79 5f 72 65 61 64 28 62 set_retry_read(b
06e0: 69 6f 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72 io);. }. r
06f0: 65 74 75 72 6e 20 72 65 74 3b 0a 7d 0a 0a 73 74 eturn ret;.}..st
0700: 61 74 69 63 20 69 6e 74 0a 42 69 6f 52 65 61 64 atic int.BioRead
0710: 20 28 62 69 6f 2c 20 62 75 66 2c 20 62 75 66 4c (bio, buf, bufL
0720: 65 6e 29 0a 20 20 20 20 42 49 4f 20 2a 62 69 6f en). BIO *bio
0730: 3b 0a 20 20 20 20 63 68 61 72 20 2a 62 75 66 3b ;. char *buf;
0740: 0a 20 20 20 20 69 6e 74 20 62 75 66 4c 65 6e 3b . int bufLen;
0750: 0a 7b 0a 20 20 20 20 54 63 6c 5f 43 68 61 6e 6e .{. Tcl_Chann
0760: 65 6c 20 63 68 61 6e 20 3d 20 54 6c 73 5f 47 65 el chan = Tls_Ge
0770: 74 50 61 72 65 6e 74 28 28 53 74 61 74 65 2a 29 tParent((State*)
0780: 62 69 6f 2d 3e 70 74 72 29 3b 0a 20 20 20 20 69 bio->ptr);. i
0790: 6e 74 20 72 65 74 20 3d 20 30 3b 0a 0a 20 20 20 nt ret = 0;..
07a0: 20 64 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c dprintf(stderr,
07b0: 22 5c 6e 42 69 6f 52 65 61 64 28 30 78 25 78 2c "\nBioRead(0x%x,
07c0: 20 3c 62 75 66 3e 2c 20 25 64 29 20 5b 30 78 25 <buf>, %d) [0x%
07d0: 78 5d 22 2c 20 62 69 6f 2c 20 62 75 66 4c 65 6e x]", bio, bufLen
07e0: 2c 20 63 68 61 6e 29 3b 0a 0a 20 20 20 20 69 66 , chan);.. if
07f0: 20 28 62 75 66 20 3d 3d 20 4e 55 4c 4c 29 20 72 (buf == NULL) r
0800: 65 74 75 72 6e 20 30 3b 0a 0a 23 69 66 64 65 66 eturn 0;..#ifdef
0810: 20 54 43 4c 5f 43 48 41 4e 4e 45 4c 5f 56 45 52 TCL_CHANNEL_VER
0820: 53 49 4f 4e 5f 32 0a 20 20 20 20 72 65 74 20 3d SION_2. ret =
0830: 20 54 63 6c 5f 52 65 61 64 52 61 77 28 63 68 61 Tcl_ReadRaw(cha
0840: 6e 2c 20 62 75 66 2c 20 62 75 66 4c 65 6e 29 3b n, buf, bufLen);
0850: 0a 23 65 6c 73 65 0a 20 20 20 20 72 65 74 20 3d .#else. ret =
0860: 20 54 63 6c 5f 52 65 61 64 28 63 68 61 6e 2c 20 Tcl_Read(chan,
0870: 62 75 66 2c 20 62 75 66 4c 65 6e 29 3b 0a 23 65 buf, bufLen);.#e
0880: 6e 64 69 66 0a 0a 20 20 20 20 64 70 72 69 6e 74 ndif.. dprint
0890: 66 28 73 74 64 65 72 72 2c 22 5c 6e 5b 30 78 25 f(stderr,"\n[0x%
08a0: 78 5d 20 42 69 6f 52 65 61 64 28 25 64 29 20 2d x] BioRead(%d) -
08b0: 3e 20 25 64 20 5b 25 64 2e 25 64 5d 22 2c 20 63 > %d [%d.%d]", c
08c0: 68 61 6e 2c 20 62 75 66 4c 65 6e 2c 20 72 65 74 han, bufLen, ret
08d0: 2c 0a 09 20 20 20 20 54 63 6c 5f 45 6f 66 28 63 ,.. Tcl_Eof(c
08e0: 68 61 6e 29 2c 20 54 63 6c 5f 47 65 74 45 72 72 han), Tcl_GetErr
08f0: 6e 6f 28 29 29 3b 0a 0a 20 20 20 20 42 49 4f 5f no());.. BIO_
0900: 63 6c 65 61 72 5f 66 6c 61 67 73 28 62 69 6f 2c clear_flags(bio,
0910: 20 42 49 4f 5f 46 4c 41 47 53 5f 52 45 41 44 7c BIO_FLAGS_READ|
0920: 42 49 4f 5f 46 4c 41 47 53 5f 53 48 4f 55 4c 44 BIO_FLAGS_SHOULD
0930: 5f 52 45 54 52 59 29 3b 0a 0a 20 20 20 20 69 66 _RETRY);.. if
0940: 20 28 72 65 74 20 3d 3d 20 30 29 20 7b 0a 09 69 (ret == 0) {..i
0950: 66 20 28 21 54 63 6c 5f 45 6f 66 28 63 68 61 6e f (!Tcl_Eof(chan
0960: 29 29 20 7b 0a 09 20 20 20 20 42 49 4f 5f 73 65 )) {.. BIO_se
0970: 74 5f 72 65 74 72 79 5f 72 65 61 64 28 62 69 6f t_retry_read(bio
0980: 29 3b 0a 09 20 20 20 20 72 65 74 20 3d 20 2d 31 );.. ret = -1
0990: 3b 0a 09 7d 0a 20 20 20 20 7d 0a 20 20 20 20 69 ;..}. }. i
09a0: 66 20 28 42 49 4f 5f 73 68 6f 75 6c 64 5f 77 72 f (BIO_should_wr
09b0: 69 74 65 28 62 69 6f 29 29 20 7b 0a 09 42 49 4f ite(bio)) {..BIO
09c0: 5f 73 65 74 5f 72 65 74 72 79 5f 77 72 69 74 65 _set_retry_write
09d0: 28 62 69 6f 29 3b 0a 20 20 20 20 7d 0a 20 20 20 (bio);. }.
09e0: 20 72 65 74 75 72 6e 20 72 65 74 3b 0a 7d 0a 0a return ret;.}..
09f0: 73 74 61 74 69 63 20 69 6e 74 0a 42 69 6f 50 75 static int.BioPu
0a00: 74 73 09 28 62 69 6f 2c 20 73 74 72 29 0a 20 20 ts.(bio, str).
0a10: 20 20 42 49 4f 20 2a 62 69 6f 3b 0a 20 20 20 20 BIO *bio;.
0a20: 63 68 61 72 20 2a 73 74 72 3b 0a 7b 0a 20 20 20 char *str;.{.
0a30: 20 72 65 74 75 72 6e 20 42 69 6f 57 72 69 74 65 return BioWrite
0a40: 28 62 69 6f 2c 20 73 74 72 2c 20 73 74 72 6c 65 (bio, str, strle
0a50: 6e 28 73 74 72 29 29 3b 0a 7d 0a 0a 73 74 61 74 n(str));.}..stat
0a60: 69 63 20 6c 6f 6e 67 0a 42 69 6f 43 74 72 6c 09 ic long.BioCtrl.
0a70: 28 62 69 6f 2c 20 63 6d 64 2c 20 6e 75 6d 2c 20 (bio, cmd, num,
0a80: 70 74 72 29 0a 20 20 20 20 42 49 4f 20 2a 62 69 ptr). BIO *bi
0a90: 6f 3b 0a 20 20 20 20 69 6e 74 20 63 6d 64 3b 0a o;. int cmd;.
0aa0: 20 20 20 20 6c 6f 6e 67 20 6e 75 6d 3b 0a 20 20 long num;.
0ab0: 20 20 63 68 61 72 20 2a 70 74 72 3b 0a 7b 0a 20 char *ptr;.{.
0ac0: 20 20 20 54 63 6c 5f 43 68 61 6e 6e 65 6c 20 63 Tcl_Channel c
0ad0: 68 61 6e 20 3d 20 54 6c 73 5f 47 65 74 50 61 72 han = Tls_GetPar
0ae0: 65 6e 74 28 28 53 74 61 74 65 2a 29 62 69 6f 2d ent((State*)bio-
0af0: 3e 70 74 72 29 3b 0a 20 20 20 20 6c 6f 6e 67 20 >ptr);. long
0b00: 72 65 74 20 3d 20 31 3b 0a 20 20 20 20 69 6e 74 ret = 1;. int
0b10: 20 2a 69 70 3b 0a 0a 20 20 20 20 64 70 72 69 6e *ip;.. dprin
0b20: 74 66 28 73 74 64 65 72 72 2c 22 5c 6e 42 69 6f tf(stderr,"\nBio
0b30: 43 74 72 6c 28 30 78 25 78 2c 20 30 78 25 78 2c Ctrl(0x%x, 0x%x,
0b40: 20 30 78 25 78 2c 20 30 78 25 78 29 22 2c 20 62 0x%x, 0x%x)", b
0b50: 69 6f 2c 20 63 6d 64 2c 20 6e 75 6d 2c 20 70 74 io, cmd, num, pt
0b60: 72 29 3b 0a 0a 20 20 20 20 73 77 69 74 63 68 20 r);.. switch
0b70: 28 63 6d 64 29 20 7b 0a 20 20 20 20 63 61 73 65 (cmd) {. case
0b80: 20 42 49 4f 5f 43 54 52 4c 5f 52 45 53 45 54 3a BIO_CTRL_RESET:
0b90: 0a 09 6e 75 6d 20 3d 20 30 3b 0a 20 20 20 20 63 ..num = 0;. c
0ba0: 61 73 65 20 42 49 4f 5f 43 5f 46 49 4c 45 5f 53 ase BIO_C_FILE_S
0bb0: 45 45 4b 3a 0a 20 20 20 20 63 61 73 65 20 42 49 EEK:. case BI
0bc0: 4f 5f 43 5f 46 49 4c 45 5f 54 45 4c 4c 3a 0a 09 O_C_FILE_TELL:..
0bd0: 72 65 74 20 3d 20 30 3b 0a 09 62 72 65 61 6b 3b ret = 0;..break;
0be0: 0a 20 20 20 20 63 61 73 65 20 42 49 4f 5f 43 54 . case BIO_CT
0bf0: 52 4c 5f 49 4e 46 4f 3a 0a 09 72 65 74 20 3d 20 RL_INFO:..ret =
0c00: 31 3b 0a 09 62 72 65 61 6b 3b 0a 20 20 20 20 63 1;..break;. c
0c10: 61 73 65 20 42 49 4f 5f 43 5f 53 45 54 5f 46 44 ase BIO_C_SET_FD
0c20: 3a 0a 09 42 69 6f 46 72 65 65 28 62 69 6f 29 3b :..BioFree(bio);
0c30: 0a 09 2f 2a 20 53 65 74 73 20 53 74 61 74 65 2a ../* Sets State*
0c40: 20 2a 2f 0a 09 62 69 6f 2d 3e 70 74 72 09 3d 20 */..bio->ptr.=
0c50: 2a 28 28 63 68 61 72 20 2a 2a 29 70 74 72 29 3b *((char **)ptr);
0c60: 0a 09 62 69 6f 2d 3e 73 68 75 74 64 6f 77 6e 09 ..bio->shutdown.
0c70: 3d 20 28 69 6e 74 29 6e 75 6d 3b 0a 09 62 69 6f = (int)num;..bio
0c80: 2d 3e 69 6e 69 74 09 3d 20 31 3b 0a 09 62 72 65 ->init.= 1;..bre
0c90: 61 6b 3b 0a 20 20 20 20 63 61 73 65 20 42 49 4f ak;. case BIO
0ca0: 5f 43 5f 47 45 54 5f 46 44 3a 0a 09 69 66 20 28 _C_GET_FD:..if (
0cb0: 62 69 6f 2d 3e 69 6e 69 74 29 20 7b 0a 09 20 20 bio->init) {..
0cc0: 20 20 69 70 20 3d 20 28 69 6e 74 20 2a 29 70 74 ip = (int *)pt
0cd0: 72 3b 0a 09 20 20 20 20 69 66 20 28 69 70 20 21 r;.. if (ip !
0ce0: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 2a 69 70 20 = NULL) {...*ip
0cf0: 3d 20 62 69 6f 2d 3e 6e 75 6d 3b 0a 09 20 20 20 = bio->num;..
0d00: 20 7d 0a 09 20 20 20 20 72 65 74 20 3d 20 62 69 }.. ret = bi
0d10: 6f 2d 3e 6e 75 6d 3b 0a 09 7d 20 65 6c 73 65 20 o->num;..} else
0d20: 7b 0a 09 20 20 20 20 72 65 74 20 3d 20 2d 31 3b {.. ret = -1;
0d30: 0a 09 7d 0a 09 62 72 65 61 6b 3b 0a 20 20 20 20 ..}..break;.
0d40: 63 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f 47 45 case BIO_CTRL_GE
0d50: 54 5f 43 4c 4f 53 45 3a 0a 09 72 65 74 20 3d 20 T_CLOSE:..ret =
0d60: 62 69 6f 2d 3e 73 68 75 74 64 6f 77 6e 3b 0a 09 bio->shutdown;..
0d70: 62 72 65 61 6b 3b 0a 20 20 20 20 63 61 73 65 20 break;. case
0d80: 42 49 4f 5f 43 54 52 4c 5f 53 45 54 5f 43 4c 4f BIO_CTRL_SET_CLO
0d90: 53 45 3a 0a 09 62 69 6f 2d 3e 73 68 75 74 64 6f SE:..bio->shutdo
0da0: 77 6e 20 3d 20 28 69 6e 74 29 6e 75 6d 3b 0a 09 wn = (int)num;..
0db0: 62 72 65 61 6b 3b 0a 20 20 20 20 63 61 73 65 20 break;. case
0dc0: 42 49 4f 5f 43 54 52 4c 5f 45 4f 46 3a 0a 09 64 BIO_CTRL_EOF:..d
0dd0: 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 printf(stderr, "
0de0: 42 49 4f 5f 43 54 52 4c 5f 45 4f 46 5c 6e 22 29 BIO_CTRL_EOF\n")
0df0: 3b 0a 09 72 65 74 20 3d 20 54 63 6c 5f 45 6f 66 ;..ret = Tcl_Eof
0e00: 28 63 68 61 6e 29 3b 0a 09 62 72 65 61 6b 3b 0a (chan);..break;.
0e10: 20 20 20 20 63 61 73 65 20 42 49 4f 5f 43 54 52 case BIO_CTR
0e20: 4c 5f 50 45 4e 44 49 4e 47 3a 0a 09 72 65 74 20 L_PENDING:..ret
0e30: 3d 20 28 54 63 6c 5f 49 6e 70 75 74 42 75 66 66 = (Tcl_InputBuff
0e40: 65 72 65 64 28 63 68 61 6e 29 20 3f 20 31 20 3a ered(chan) ? 1 :
0e50: 20 30 29 3b 0a 09 64 70 72 69 6e 74 66 28 73 74 0);..dprintf(st
0e60: 64 65 72 72 2c 20 22 42 49 4f 5f 43 54 52 4c 5f derr, "BIO_CTRL_
0e70: 50 45 4e 44 49 4e 47 28 25 64 29 5c 6e 22 2c 20 PENDING(%d)\n",
0e80: 72 65 74 29 3b 0a 09 62 72 65 61 6b 3b 0a 20 20 ret);..break;.
0e90: 20 20 63 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f case BIO_CTRL_
0ea0: 57 50 45 4e 44 49 4e 47 3a 0a 09 72 65 74 20 3d WPENDING:..ret =
0eb0: 20 30 3b 0a 09 62 72 65 61 6b 3b 0a 20 20 20 20 0;..break;.
0ec0: 63 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f 44 55 case BIO_CTRL_DU
0ed0: 50 3a 0a 09 62 72 65 61 6b 3b 0a 20 20 20 20 63 P:..break;. c
0ee0: 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f 46 4c 55 ase BIO_CTRL_FLU
0ef0: 53 48 3a 0a 09 64 70 72 69 6e 74 66 28 73 74 64 SH:..dprintf(std
0f00: 65 72 72 2c 20 22 42 49 4f 5f 43 54 52 4c 5f 46 err, "BIO_CTRL_F
0f10: 4c 55 53 48 5c 6e 22 29 3b 0a 09 69 66 20 28 0a LUSH\n");..if (.
0f20: 23 69 66 64 65 66 20 54 43 4c 5f 43 48 41 4e 4e #ifdef TCL_CHANN
0f30: 45 4c 5f 56 45 52 53 49 4f 4e 5f 32 0a 09 20 20 EL_VERSION_2..
0f40: 20 20 54 63 6c 5f 57 72 69 74 65 52 61 77 28 63 Tcl_WriteRaw(c
0f50: 68 61 6e 2c 20 22 22 2c 20 30 29 20 3e 3d 20 30 han, "", 0) >= 0
0f60: 0a 23 65 6c 73 65 0a 09 20 20 20 20 54 63 6c 5f .#else.. Tcl_
0f70: 46 6c 75 73 68 28 63 68 61 6e 29 20 3d 3d 20 54 Flush(chan) == T
0f80: 43 4c 5f 4f 4b 0a 23 65 6e 64 69 66 0a 09 20 20 CL_OK.#endif..
0f90: 20 20 29 20 7b 0a 09 20 20 20 20 72 65 74 20 3d ) {.. ret =
0fa0: 20 31 3b 0a 09 7d 20 65 6c 73 65 20 7b 0a 09 20 1;..} else {..
0fb0: 20 20 20 72 65 74 20 3d 20 2d 31 3b 0a 09 7d 0a ret = -1;..}.
0fc0: 09 62 72 65 61 6b 3b 0a 20 20 20 20 64 65 66 61 .break;. defa
0fd0: 75 6c 74 3a 0a 09 72 65 74 20 3d 20 30 3b 0a 09 ult:..ret = 0;..
0fe0: 62 72 65 61 6b 3b 0a 20 20 20 20 7d 0a 20 20 20 break;. }.
0ff0: 20 72 65 74 75 72 6e 28 72 65 74 29 3b 0a 7d 0a return(ret);.}.
1000: 0a 73 74 61 74 69 63 20 69 6e 74 0a 42 69 6f 4e .static int.BioN
1010: 65 77 09 28 62 69 6f 29 0a 20 20 20 20 42 49 4f ew.(bio). BIO
1020: 20 2a 62 69 6f 3b 0a 7b 0a 20 20 20 20 62 69 6f *bio;.{. bio
1030: 2d 3e 69 6e 69 74 09 3d 20 30 3b 0a 20 20 20 20 ->init.= 0;.
1040: 62 69 6f 2d 3e 6e 75 6d 09 3d 20 30 3b 0a 20 20 bio->num.= 0;.
1050: 20 20 62 69 6f 2d 3e 70 74 72 09 3d 20 4e 55 4c bio->ptr.= NUL
1060: 4c 3b 0a 20 20 20 20 62 69 6f 2d 3e 66 6c 61 67 L;. bio->flag
1070: 73 09 3d 20 30 3b 0a 0a 20 20 20 20 72 65 74 75 s.= 0;.. retu
1080: 72 6e 20 31 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 rn 1;.}..static
1090: 69 6e 74 0a 42 69 6f 46 72 65 65 09 28 62 69 6f int.BioFree.(bio
10a0: 29 0a 20 20 20 20 42 49 4f 20 2a 62 69 6f 3b 0a ). BIO *bio;.
10b0: 7b 0a 20 20 20 20 69 66 20 28 62 69 6f 20 3d 3d {. if (bio ==
10c0: 20 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 75 72 6e NULL) {..return
10d0: 20 30 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 69 0;. }.. i
10e0: 66 20 28 62 69 6f 2d 3e 73 68 75 74 64 6f 77 6e f (bio->shutdown
10f0: 29 20 7b 0a 09 69 66 20 28 62 69 6f 2d 3e 69 6e ) {..if (bio->in
1100: 69 74 29 20 7b 0a 09 20 20 20 20 2f 2a 73 68 75 it) {.. /*shu
1110: 74 64 6f 77 6e 28 62 69 6f 2d 3e 6e 75 6d 2c 20 tdown(bio->num,
1120: 32 29 20 2a 2f 0a 09 20 20 20 20 2f 2a 63 6c 6f 2) */.. /*clo
1130: 73 65 73 6f 63 6b 65 74 28 62 69 6f 2d 3e 6e 75 sesocket(bio->nu
1140: 6d 29 20 2a 2f 0a 09 7d 0a 09 62 69 6f 2d 3e 69 m) */..}..bio->i
1150: 6e 69 74 09 3d 20 30 3b 0a 09 62 69 6f 2d 3e 66 nit.= 0;..bio->f
1160: 6c 61 67 73 09 3d 20 30 3b 0a 09 62 69 6f 2d 3e lags.= 0;..bio->
1170: 6e 75 6d 09 3d 20 30 3b 0a 20 20 20 20 7d 0a 20 num.= 0;. }.
1180: 20 20 20 72 65 74 75 72 6e 20 31 3b 0a 7d 0a return 1;.}.