[comp.sys.next] Outlets and Disappearing Variables

carlos@piglet.caltech.edu (07/13/90)

Outlet Initialization

When are outlet setting methods, setVariableName:anObject, called?
Aren't they messaged immediately after the nib segment is loaded with
loadNibSegment?

The problem is that I have a module which is not setting the outlets after the
nib segment is loaded. Everything is connected in Interface Builder, any
pointers, suggestions?

Instance Variables Disappearing

In the same object referred to above, my instance variables are disapppearing.
With GDB, I'm able to deterine that they exist (have values) within the method
in which they are set, but everywhere else they are null. How, why is this 
happening?

Thanks in advance!

Carlos Salinas-------Use the NeXT Luke, succumb to the dark side of the cube!
carlos@eeyore.caltech.edu <- NeXT Mail-------But which side is the dark side?

carlos@eeyore.caltech.edu (07/13/90)

I figured out what the problem was. I had an instantiation of the nibs owner
object in the nib file itself. So I thought I had one object when I actually
had two, and the instance variables were split amongst them.

OK... That bug is solved. Now for a stream related bug.

The situation...
I have an object, Telnet, which connects to Internet via TCP-IP. It creates
a socket, connects a file (pipe) to it and sets up a DPS event for incoming
data, and a stream on that file. The problem is in reading the stream. The
program freezes up. It's reads data from the stream fine. When it reaches the
end, it does an NXFill and disappears into a read (see backtrace below.)
I've included the Telnet object source and a gdb backtrace.

BTW- If you notice any glaring errors in the other stuff, please tell me.

Carlos Salinas
carlos@eeyore.caltech.edu <- NeXT Mail

(gdb) bt
#0  0x502a492 in read ()
#1  0x50101c8 in NXFill ()
#2  0x5011dc8 in _NXStreamFillBuffer ()
#3  0x286c in readline (st=(struct _NXStream *) 0x620c0, buf=(char *) 0x3fff728 "\377\375\030\001") (Telnet.m line 47)
#4  0x2a94 in - [Telnet=0x00017020 readStream] (Telnet.m line 112)
#5  0x27f4 in handle_socket_input (fd=3, self=(id) 0x17020) (Telnet.m line 33)
#6  0x606c9ec in checkFDs ()
#7  0x606c3ce in _DPSGetOrPeekEvent ()
#8  0x6007872 in - [Application run]
#9  0x2c24 in main (argc=1, argv=(char **) 0x3fffea4) (TCP-IP_main.m line 12)
End of backtrace: saved frame pointer is zero.

/* Generated by Interface Builder */

#import "Telnet.h"

#import <appkit/Application.h>
#import <appkit/Responder.h>
#import <appkit/Panel.h>
#import <appkit/ScrollView.h>
#import <appkit/Window.h>
#import <appkit/graphics.h>
#import <appkit/Text.h>

#import <dpsclient/dpsclient.h>
#import <sys/socket.h>

#import <sys/boolean.h>
#import <stdlib.h>
#import <libc.h>

#import <arpa/inet.h>
#import <streams/streams.h>

#define PRIORITY 1		/* socket input priority. */ 


@implementation Telnet

/* Called when data is detected in socket. Passes data to input handler. */
static void handle_socket_input(fd,self)
int fd;
id self;
{
	[self readStream];
}

/* Reads a \n delimited line from the stream into a buffer.
   Avoids overflowing strings.
*/
char *readline (st, buf)
NXStream *st;
char buf[];
{
	char *pt;
	int c;
	
	pt = &buf[0];
	for (c = NXGetc (st); !NXAtEOS (st) && (c != '\n'); c = NXGetc (st)) {
		*pt++ = c;
		}
	if (NXAtEOS (st)) return NULL;
	else {
		*pt++ = c;
		*pt = 0;
		return buf;
		}
}

/* Open a connection to sock_addr. */
+ open:(struct sockaddr_in *)sock_addr title:(char *)title
{
	NXRect frame;
	frame.origin.x=1120/2;	/* Screen origin x. */
	frame.origin.y=832/2;	/* Screen origin y. */

	self = [super new];
	[NXApp loadNibSection:"telnet.nib" owner:self];

	/* Open a socket. */
	if ((theSocket = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
		perror("TCP-IP");
		NXRunAlertPanel(NULL,"Couldn't open socket",NULL,NULL,NULL);
		return self;
	}

	/* Establish connection to host. */
	if (connect(theSocket, sock_addr, sizeof(struct sockaddr_in))==-1) {
		perror("TCP-IP");
		NXRunAlertPanel(NULL,"Couldn't connect to socket.",NULL,NULL,NULL);
		return self;
	}

	/* Add socket to DPS event queue. DPSAddFD */
	/* fcntl(theSocket, F_SETFL, FNDELAY);	*/ /* Do we need this? */
	DPSAddFD(theSocket,&handle_socket_input,self,PRIORITY);

	/* Open a stream to the socket. */
	stream=NXOpenFile(theSocket, NX_READWRITE);

/*	[disconnectMenu setEnabled:YES];		*//* Enable disconnect. */
	
    return self;
}

/* Called when the output window is closed or from disconnect menu. */
- close:sender
{
	NXClose(stream);
	DPSRemoveFD(theSocket);
	close(theSocket);
	[super free];

	return self;
}

- readStream
{
	int where=[text textLength];
	char buffer[512];

	while (readline(stream,buffer)) {	
		[text setSel:where :where];
		[text replaceSel:buffer];
	}
	return self;	
}

- writeStream:(char)data
{
	NXPutc(stream,data);
	NXFlush(stream);
	return self; 
}

- setTextWindow:anObject
{
	textWindow = anObject;
	[textWindow makeKeyAndOrderFront:self];
	return self;
}

- setTextDisplay:anObject
{
    textDisplay = anObject;
    text=[textDisplay docView];    
    return self;
}

@end