Work on proxy.
[yazpp-moved-to-github.git] / include / yaz-pdu-assoc.h
1 /*
2  * Copyright (c) 1998-1999, Index Data.
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  * 
6  * $Id: yaz-pdu-assoc.h,v 1.6 1999-11-10 10:02:34 adam Exp $
7  */
8
9 #include <comstack.h>
10 #include <yaz-socket-observer.h>
11 #include <yaz-pdu-observer.h>
12
13 /** Simple Protocol Data Unit Assocation.
14     This object sends - and receives PDU's using the COMSTACK
15     network utility. To use the association in client role, use
16     the method connect. The server role is initiated by using the
17     listen method.
18  */
19 class YAZ_EXPORT Yaz_PDU_Assoc : public IYaz_PDU_Observable, IYazSocketObserver {
20  private:
21     enum { Connecting, Connected, Listen, Ready, Closed } m_state;
22     class PDU_Queue {
23     public:
24         PDU_Queue(const char *buf, int len);
25         PDU_Queue::~PDU_Queue();
26         char *m_buf;
27         int m_len;
28         PDU_Queue *m_next;
29     };
30     Yaz_PDU_Assoc *m_parent;
31     Yaz_PDU_Assoc *m_children;
32     Yaz_PDU_Assoc *m_next;
33     COMSTACK Yaz_PDU_Assoc::comstack();
34     COMSTACK m_cs;
35     IYazSocketObservable *m_socketObservable;
36     IYaz_PDU_Observer *m_PDU_Observer;
37     char *m_input_buf;
38     int m_input_len;
39     PDU_Queue *m_queue_out;
40     int Yaz_PDU_Assoc::flush_PDU();
41     int *m_destroyed;
42     int m_idleTime;
43  public:
44     /// Create object using specified socketObservable
45     Yaz_PDU_Assoc(IYazSocketObservable *socketObservable, COMSTACK cs = 0);
46     /// Close socket and destroy object.
47     virtual ~Yaz_PDU_Assoc();
48     /// Clone the object
49     IYaz_PDU_Observable *clone();
50     /// Send PDU
51     int send_PDU(const char *buf, int len);
52     /// connect to server (client role)
53     void connect(IYaz_PDU_Observer *observer, const char *addr);
54     /// listen for clients (server role)
55     void listen(IYaz_PDU_Observer *observer, const char *addr);
56     /// Socket notification
57     void socketNotify(int event);
58     /// Close socket
59     void close();
60     /// Close and destroy
61     void destroy();
62     /// Set Idle Time
63     void idleTime (int timeout);
64 };