discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

conflict with NSRunLoop and run loop of c library


From: Sebastian Reitenbach
Subject: conflict with NSRunLoop and run loop of c library
Date: Sun, 30 Jun 2013 19:32:04 +0200
User-agent: SOGoMail 2.0.6a

Hi,

I wrote a wrapper around libpcap, to finally write a tool, sniffing the network.
So far, so good. My sniffer tool, configures libpcap to either listen on a 
network interface,
or read input from a captured file. After its configured, it starts pcap to get 
it to do its job
calling pcap_loop()
My tool receives the traffic, parsing it, and itssaving interesting sniffed 
traffic into a 
sqlite database using libSQLClient.

So far, so good. Now I wanted to have another part of the tool firing up a 
webserver, so 
that I can connect to it with a brower. Its supposed to show me the sniffed 
values.

In my tools main() I started the web server like in the testWebServer.m 
that comes with the WebServer library.

kind of:
  [server setDelegate: handler];
  [server setPort: [defs stringForKey: @"Port"] secure: nil];
  [server setVerbose: [defs boolForKey: @"Debug"]];
  [[NSRunLoop currentRunLoop] run];

But now, when I connect to the webserver with my browser, it gives me a webpage.
Thats great! ;) But the NSRunLoop line seems to prevent the libpcap loop to run 
:(

So, I thought hey, lets put the webserver into an own thread, and start the 
runloop there.
Basically I now have this in my tools main function to start a thread for the 
webserver:


  wsHandler = [WebServerHandler new];
  [wsHandler setWebServerPort: serverPort];
  [wsHandler setWebServerDebug: serverDebug];
  [NSThread detachNewThreadSelector:@selector(runWebserver)
                           toTarget: wsHandler
                         withObject: nil];

and in the WebServerHandler the runWebserver method looks like:
- (void)runWebserver
{
  NSAutoreleasePool *pool;
  pool = [NSAutoreleasePool new];
NSLog(@"runWebserver got called");
  WebServer *webServer = [WebServer new];
NSLog(@"runWebserver got called");
  [webServer setPort:serverPort secure:nil];
  [webServer setVerbose: serverDebug];
  [webServer setDelegate: self];
  [[NSRunLoop currentRunLoop] run];
  [pool release];
}

But now, the "runWebserver got called" is only printed once.
The webserver has the port open, and listens, but not answering.
But pcap_loop now works.

I guess, I'm doing something wrong. Somebody can beat me with a cluestick?

As an easy solution, I could likely split the functionality into two programs.
One sniffing, and saving into the sqlite database, and the other reading from
it and providing the web page. But I thought there must be a way to 
have both in a single program.

thanks,
Sebastian





reply via email to

[Prev in Thread] Current Thread [Next in Thread]