Saner handling if config.mk doesn't exist: use a default config.defaults.mk.
[wvstreams.git] / include / wvudp.h
blob08ed47288a034a5c24c4aeba6334944064e3a000
1 /* -*- Mode: C++ -*-
2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
5 */
6 #ifndef __WVUDP_H
7 #define __WVUDP_H
9 #include "wvfdstream.h"
10 #include "wvaddr.h"
12 /**
13 * WvUDPStream can send and receive packets on a connectionless UDP socket.
15 * In the constructor, the socket is attached using bind() to the given
16 * _local address. If the address is 0.0.0.0, all addresses on the local
17 * host are used; if the port is 0, an available port number is chosen
18 * automatically.
20 * If the _rem address is 0.0.0.0, the port is not connect()ed. That means
21 * it can receive packets from anywhere and send them to anywhere. The
22 * src() and setdest() functions are useful for this. If _rem is not 0.0.0.0,
23 * connect() is called and the socket will only accept data to/from the
24 * specified remote UDP address.
26 * Buffering: all the usual WvStream-style input buffering is available,
27 * including getline(), but because input packets may get lost it is of
28 * limited usefulness. Buffering will cause particular confusion if the
29 * socket is not connect()ed.
31 class WvUDPStream : public WvFDStream
33 public:
34 /** connect a new socket */
35 WvUDPStream(const WvIPPortAddr &_local, const WvIPPortAddr &_rem);
36 virtual ~WvUDPStream();
38 const WvAddr *local() const;
40 /**
41 * return the remote address (source of incoming packets, target of
42 * outgoing packets). This is the last host sent to or received from,
43 * whichever was more recent.
45 virtual const WvAddr *src() const;
46 void setdest(const WvIPPortAddr &_remaddr)
47 { remaddr = _remaddr; }
49 void enable_broadcasts();
51 protected:
52 WvIPPortAddr localaddr, remaddr;
54 virtual size_t uread(void *buf, size_t count);
55 virtual size_t uwrite(const void *buf, size_t count);
57 public:
58 const char *wstype() const { return "WvUDPStream"; }
62 #endif // __WVUDP_H