fb_thread.cc 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. #include "win.hh"
  9. #include "network/net_sock.hh"
  10. #include "url.hh"
  11. #include "threads/threads.hh"
  12. void fb_thread(void *context)
  13. {
  14. fb_thread_window *w=(fb_thread_window *)context;
  15. w->state=FB_WAITING;
  16. while (w->state!=FB_THREAD_QUITING)
  17. {
  18. if (w->stopping)
  19. {
  20. w->stopping=0;
  21. w->last_error=FB_USER_ABORTED;
  22. w->state=FB_DONE_READING;
  23. }
  24. switch (w->state)
  25. {
  26. case FB_CONNECTING :
  27. {
  28. if (w->sock)
  29. delete w->sock;
  30. w->sock=w->url->connect_to_server(w->prot);
  31. if (w->sock)
  32. w->state=FB_READING;
  33. else
  34. {
  35. w->last_error=FB_NO_CONNECT;
  36. w->state=FB_DONE_READING;
  37. }
  38. w->last_read.get();
  39. } break;
  40. case FB_READING :
  41. {
  42. if (!w->sock)
  43. w->state=FB_WAITING;
  44. else
  45. {
  46. if (w->sock->ready_to_read())
  47. w->read_data();
  48. else
  49. w->check_for_timeout();
  50. }
  51. } break;
  52. case FB_SUSPENDED_READ :
  53. w->last_read.get(); // intentional no-break
  54. default:
  55. i4_thread_yield();
  56. break;
  57. }
  58. }
  59. w->state=FB_THREAD_DONE;
  60. }