Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

[FIXED] Segmentation Error when Selector.open

Moderators: kris

Posted: 04/20/10 09:19:47 Modified: 04/20/10 10:01:40

I'm trying to developper a server using Selector. My first attempt is a combine of examples found in AbstractSelector and Selector modules.

I get an "Segmentation Error" when "selector.open(2, 2)" It using Epoll because I'm on linux with ldc, dsss and libtango-ldc-dev (0.99.9+svn5428.dfsg-0ubuntu0)

There is the source code without logging:

Selector selector;
Socket conduit1, conduit2;
uint event_count;

A a1, a2; a1 = new A; a2 = new A;

selector.open(2, 2); // Segmentation Error
selector.register(conduit1, Event.Read, a1);
selector.register(conduit2, Event.Write, a2);
event_count = selector.select;
try
{
	if( event_count > 0)
	{
		char[16] buffer;
		int count;
		foreach( SelectionKey key; selector.selectedSet )
		{
			if( key.isReadable )
			{
				count = (cast(Socket) key.conduit).read(buffer);
				if( count != IConduit.Eof )
					selector.register(key.conduit, Event.Write, key.attachment);
				else
				{
					selector.unregister(key.conduit);
					(cast(Socket) key.conduit).close;
				}
			}

			if( key.isWritable )
			{
				count = (cast(Socket) key.conduit).write("MESSAGE");
				if( count != IConduit.Eof )
					selector.register(key.conduit, Event.Read, key.attachment);
				else
				{
					log.warn("Closing peer");
					selector.unregister(key.conduit);
					(cast(Socket) key.conduit).close;
				}
			}

			if( key.isError || key.isHangup || key.isInvalidHandle )
				selector.unregister(key.conduit);
		}
	}
	else if( event_count == 0 ) ;
	else if( event_count == -1 ) ;
}
catch( SelectorException e ) ;
selector.close;
Author Message

Posted: 04/20/10 10:01:17

Oups, n00b error: I forgot to instanciate the selector