summaryrefslogtreecommitdiff
path: root/include/Socket.h
blob: 89df89f8889e622fa1da3956a07dad029397085a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
 *  Baltisot
 *  Copyright (C) 1999-2008 Nicolas "Pixel" Noble
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef __SOCKET_H__
#define __SOCKET_H__

#include <Handle.h>
#include <BString.h>
#include <Output.h>
#include <Input.h>
#include <Exceptions.h>

class Socket : public Handle {
  public:
      Socket() throw (GeneralException);
      Socket(const Socket &);
      virtual ~Socket() { if (!IsClosed()) { nclose(); tagclose(); } }
    bool SetLocal(const String &, int = 0);
    bool Connect(const String &, int);
    bool Listen();
    Socket Accept() throw (GeneralException);
    bool IsConnected();
    bool IsConnecting();
    bool IsListening();
    virtual bool CanRead();
    virtual bool CanWrite();
    virtual String GetName();
    int GetPort();
    Uint32 GetAddr();
    int GetDistantPort();
    Uint32 GetDistantAddr();
    void CloseWrite();
    void CloseRead();
    bool FinalizeConnect();
    static Socket CreatePair() throw (GeneralException);
    Socket GetPair() throw (GeneralException);
  protected:
    virtual ssize_t nwrite(const void *, size_t) throw (GeneralException);
    virtual ssize_t nread(void *, size_t) throw (GeneralException);
    virtual int ndup() const throw (GeneralException);
    virtual int nclose() throw (GeneralException);

  private:
      Socket(int s, int p = -1);
    bool connected, listening, writeclosed, readclosed, connecting;
    int pair;
};

#endif