[net.dcom] O_NDELAY and CLOCAL

dennis@rlgvax.UUCP (Dennis Bednar) (01/08/86)

I have uncovered some bugs in C-kermit that I think relate to
the use of the open() O_NDELAY and fcntl() to turn off O_NDELAY.

Bug #1 is replicated as follows:
	# the following are commands typed in during interactive mode
	# this is a comment line
	set modem hayes
	set line /dev/tty20	# opens with O_NDELAY
	set speed 1200
	set esc 1
	set modem dir		# change dialup line *back* to hardwired
	connect
	(C-Kermit will print a Communications line failure message.)
	(The bug is caused by the second set modem dir command)
	(Doing a connect without the extra set modem dir is okay).

Bug # 2 is replicated as follows:
	# the following are commands typed in during interactive mode
	set modem hayes
	# assume line tty23 does NOT have any wire plugged into it
	set line /dev/tty23	# opens with O_NDELAY, evident by debug code
	set esc 1
	set sp 1200
	dial 6483300		# dial code turns on CLOCAL
				# dial code turns off O_NDELAY
				# dial code attempts to tell modem to dial
				# but there is no modem, in fact,
				# there is no carrier since there is
				# no device on that port
				# dial code fails to dial
				# dial code turns off CLOCAL
				# dial code prints message that cannot phone
	quit			# at this point kermit hangs on the
				# close() system call, verified
				# by running gcore(1), and then
				# adb on the core.pid file

				# PS, doing a set line command
				# for a different port will also
				# tickle the bug, since kermit
				# first closes any open ttyfd
				# before opening a new tty line
	Why should kermit hang on a close?
	PS, one of control-\ or the escape char (I forget) is needed
	to interrupt.
	I tried to use an ioctl() to flush the output queues before
	the close, but that didn't help.  Could it be that
	RTS is stuck high waiting for CTS?

I would like to know exactly what the O_NDELAY bit does, and
exactly what the CLOCAL bit does.

Heres what I understand so far:
	open with O_NDELAY returns an open file descriptor
	even though carrier may not be present.

More questions:

	Now if you write, without carrier, does write block,
	return 0, or return -1?

	Now if you read, without carrier, does read block,
	return 0, or return -1?

	What is the purpose of using fcntl() to turn off the
	O_NDELAY, later, after the tty port is open? Now after
	you read or write, how does it change the value of
	the return code returned, assuming no carrier?

	What exactly does the CLOCAL bit do? Our local OS
	expert says that
		CLOCAL = 1 = assumes direct line that doesn't
		provide carrier, so pretend as if I got it,
		(turn on a bit in the tty structure) even
		though carrier may not be really present.

		CLOCAL = 1 = assume dialup line with modem,
		which, means that carrier must be present
		to do i/o.
	If so, then it seems that both O_NDELAY and CLOCAL
	both have something to do with carrier.  This seems
	confusing to me.

	Does CLOCAL have anything to do with RTS/CTS (request
	to send/ clear to send) handshaking?


I was tempted to write an interactive test program to put a tty port
through its paces and emperically find the answer to these
questions, but I don't have the time, and I'm stuck on another
project.

-- 
Dennis Bednar	Computer Consoles Inc.	Reston VA	703-648-3300
{decvax,ihnp4,harpo,allegra}!seismo!rlgvax!dennis
dennis@rlgvax.UUCP