Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2001-10-25
23:14 • Ticket [219137ffff] stdin is a file; it should be a socket status still Clos... artifact: 8d668c02cf user: dkf
22:52 • Ticket [219137ffff]: 2 changes artifact: 503640cc14 user: dkf
22:52 • Closed ticket [219137ffff]. artifact: caf9f79d92 user: dkf
2001-10-24
23:27 • Open ticket [219137ffff]. artifact: ffc87af0b0 user: dgp
2001-06-18
21:49 • Closed ticket [219137ffff]. artifact: 8364ec2a05 user: dkf
2001-06-06
19:51 • Ticket [219137ffff]: 4 changes artifact: a4f42f143c user: dkf
19:51 • Ticket [219137ffff]: 4 changes artifact: 56fd092f79 user: dkf
19:51 • Add attachment unixchantype.patch to ticket [219137ffffffffff|219137fff... artifact: d6512aed10 user: dkf
19:50 • Ticket [219137ffff] stdin is a file; it should be a socket status still Open... artifact: 201e38fa5c user: dkf
17:38 • Ticket [219137ffff]: 8 changes artifact: ab99fbba6b user: dkf
2001-04-01
01:47 • Ticket [219137ffff]: 2 changes artifact: efb5c975ed user: dgp
2000-11-10
20:36 • Ticket [219137ffff]: 5 changes artifact: 7a9ab2a8f0 user: dkf
2000-10-26
05:02 • New ticket [219137ffff]. artifact: dc888e265a user: nobody

stdin is a file; it should be a socket

Closed / Fixed219137ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 25 years ago
Descriptionplain2000-10-26 05:02:13
OriginalBugID: 621 RFE
Version: 8.1a2
SubmitDate: '1998-05-25'
LastModified: '1999-03-23'
Severity: LOW
Status: Assigned
Submitter: hershey
ChangedBy: surles
OS: All
OSVersion: NA
Machine: NA
FixedDate: '2000-10-25'
FixedInVersion: NA
ClosedDate: '2000-10-25'


I have a Tcl script started from the inetd daemon but am unable to get

[fconfigure stdin -peername] because stdin is a 'file' rather than a

'socket'.  The following patch to tcl8.1a2/unix/tclUnixChan.c (v 1.217)

modifies the Tcl_MakeFileChannel() function to make a channel with the

socket ('tcp') channel type if it responds sucessfully to a

getsockname() request.



Could you please include this change in future versions of Tcl?  If you

are the wrong person to send this to please let me know.



I have to say that the SUPPORTS_TTY logic in Tcl_OpenFileChannel()

should probably also be present in the Tcl_MakeFileChannel() function as

well.

---

Matthew Costello

(619)485-2926

[email protected]

*** tclUnixChan.c.ORIG  Fri Feb 20 15:20:43 1998

--- tclUnixChan.c       Thu Apr 30 16:10:49 1998

***************

*** 1387,1392 ****

--- 1387,1398 ----

      char channelName[16 + TCL_INTEGER_SPACE];

      int fd = (int) handle;

      ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);

+     Tcl_ChannelType *channelTypePtr;

+ #define SUPPORTS_SOCKET

+ #ifdef SUPPORTS_SOCKET

+     struct sockaddr sockaddr;

+     int socklen = sizeof(sockaddr);

+ #endif

  

      if (mode == 0) {

          return NULL;

***************

*** 1410,1418 ****

      fsPtr->nextPtr = tsdPtr->firstFilePtr;

      tsdPtr->firstFilePtr = fsPtr;

  

      fsPtr->fd = fd;

      fsPtr->validMask = mode | TCL_EXCEPTION;

!     fsPtr->channel = Tcl_CreateChannel(&fileChannelType, channelName,

              (ClientData) fsPtr, mode);

      

      return fsPtr->channel;

--- 1416,1441 ----

      fsPtr->nextPtr = tsdPtr->firstFilePtr;

      tsdPtr->firstFilePtr = fsPtr;

  

+ #ifdef SUPPORTS_SOCKET

+     if (getsockname(fd,&sockaddr,&socklen ) == 0) {

+       /*

+       * Initialize the serial port to a set of sane parameters.

+       * Especially important if the remote device is set to echo and

+       * the serial port driver was also set to echo -- as soon as a char

+       * were sent to the serial port, the remote device would echo it,

+       * then the serial driver would echo it back to the device, etc.

+       */

+       

+       channelTypePtr = &tcpChannelType;

+     } else 

+ #endif        /* SUPPORTS_SOCKET */

+     {

+       channelTypePtr = &fileChannelType;

+     }

+ 

      fsPtr->fd = fd;

      fsPtr->validMask = mode | TCL_EXCEPTION;

!     fsPtr->channel = Tcl_CreateChannel(channelTypePtr, channelName,

              (ClientData) fsPtr, mode);

      

      return fsPtr->channel;
dkfplain2000-11-10 20:36:36
Sounds like a reasonable request to me, though it is a UNIX-specific change as Windows places sockets and pipes/terminals into mutually exclusive sets.  Stupid operating system...

I wouldn't fix it exactly as described though; if we are going to allow stdio channels to be represented as socket channels, then they should have names from the sock* series as well.  Also ought to check errno to figure out if we've really got a socket (succeeds => yes, fails with errno==ENOTSOCK => no, other failures => machine is very short of resources!)
dgp Ticket [219137ffff]: 2 changes [History diff]2001-04-01 01:47:33
dkfplain2001-06-06 17:38:10
File Added - 7062: chantype.patch

Logged In: YES 
user_id=79902

After investigation, I've got a solution for this (well, one
that goes a bit better and handles serial lines as well.)
dkfplain2001-06-06 19:50:03
File Deleted - 7062:
dkfplain2001-06-06 19:51:49
Logged In: YES 
user_id=79902

(Bah! Next time check that it really works *first*; this new
version seems to do the business though.)
dkfplain2001-06-06 19:51:50
File Added - 7067: unixchantype.patch
dkf Closed ticket [219137ffff]. [History diff]2001-06-18 21:49:32
dgpplain2001-10-24 23:27:06
Logged In: YES 
user_id=80530

Re-opening this patch since it appears to
have introduced new bugs.

http://sf.net/tracker/?func=detail&atid=110894&aid=471374&group_id=10894

http://sf.net/tracker/index.php?func=detail&aid=465761&group_id=12997&atid=112997
dkf Closed ticket [219137ffff]. [History diff]2001-10-25 22:52:56
dkf Ticket [219137ffff]: 2 changes [History diff]2001-10-25 22:52:57
dkf Ticket [219137ffff]: 4 changes [History diff]2001-10-25 23:14:14
Log in (anonymous is fine) to add a comment.

Attachments: