source: golgotha/src/test/web_crawl/fb_thread.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 14 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 1.7 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#include "win.hh"
10#include "network/net_sock.hh"
11#include "url.hh"
12#include "threads/threads.hh"
13
14void fb_thread(void *context)
15{
16  fb_thread_window *w=(fb_thread_window *)context;
17  w->state=FB_WAITING;
18
19
20  while (w->state!=FB_THREAD_QUITING)
21  {
22    if (w->stopping)
23    {
24      w->stopping=0;
25      w->last_error=FB_USER_ABORTED;
26      w->state=FB_DONE_READING;
27    }
28   
29    switch (w->state)
30    {
31      case FB_CONNECTING :
32      {
33        if (w->sock)
34          delete w->sock;
35
36        w->sock=w->url->connect_to_server(w->prot);
37       
38        if (w->sock)
39          w->state=FB_READING;
40        else
41        {
42          w->last_error=FB_NO_CONNECT;
43          w->state=FB_DONE_READING;
44        }
45       
46        w->last_read.get();
47       
48      } break;
49       
50      case FB_READING :
51      {
52        if (!w->sock)
53          w->state=FB_WAITING;
54        else
55        {
56          if (w->sock->ready_to_read())
57            w->read_data();
58          else
59            w->check_for_timeout();         
60        }
61      } break;
62
63
64
65      case FB_SUSPENDED_READ :
66        w->last_read.get();      // intentional no-break
67      default:
68        i4_thread_yield();
69        break;
70    }
71  }
72 
73  w->state=FB_THREAD_DONE;
74}
75
Note: See TracBrowser for help on using the repository browser.