7 #include "wvistreamlist.h"
8 #include "wvunixlistener.h"
9 #include "wvunixsocket.h"
10 #include "wvstringmask.h"
11 #include "wvmoniker.h"
12 #include "wvlinkerhack.h"
19 # include <sys/types.h>
30 # include <sys/stat.h>
33 # include <sys/socket.h>
39 # include <netinet/in.h>
42 # if HAVE_NETINET_IN_SYSTM_H
43 # include <netinet/in_systm.h>
45 # include <netinet/ip.h>
47 #if HAVE_NETINET_TCP_H
48 # include <netinet/tcp.h>
72 l->
addwrap(wv::bind(&IWvStream::create, wrapper, _1));
82 if (b.peekch() ==
':')
88 l->
addwrap(wv::bind(&IWvStream::create, wrapper, _1));
108 setfd(socket(PF_UNIX, SOCK_STREAM, 0));
116 fcntl(
getfd(), F_SETFD, FD_CLOEXEC);
117 fcntl(
getfd(), F_SETFL, O_RDWR|O_NONBLOCK);
119 sockaddr *sa = addr.sockaddr();
120 if (connect(
getfd(), sa, addr.sockaddr_len()) < 0)
130 WvUnixConn::~WvUnixConn()
146 WvUnixListener::WvUnixListener(
const WvUnixAddr &_addr,
int create_mode)
164 sockaddr *sa = addr.sockaddr();
165 size_t salen = addr.sockaddr_len();
167 if (connect(
getfd(), sa, salen) == 0)
176 oldmask = umask(0777);
177 umask(oldmask | ((~create_mode) & 0777));
181 if (bind(
getfd(), sa, salen) || listen(
getfd(), 50))
193 WvUnixListener::~WvUnixListener()
199 void WvUnixListener::close()
216 struct sockaddr_un saun;
217 socklen_t len =
sizeof(saun);
219 if (!
isok())
return NULL;
221 int newfd =
::accept(getfd(), (
struct sockaddr *)&saun, &len);
224 else if (errno == EAGAIN || errno == EINTR)
240 list->append(conn,
true,
"WvUnixConn");
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
A raw memory read-only buffer backed by a constant WvString.
The basic interface which is included by all other XPLC interfaces and objects.
A Unix domain socket address is really just a filename.
void setfd(int fd)
Sets the file descriptor for both reading and writing.
virtual void seterr(int _errnum)
Set the errnum variable – we have an error.
void set_close_on_exec(bool close_on_exec)
Make the fds on this stream close-on-exec or not.
A class used to provide a masked lookup for characters in a string.
int getfd() const
Returns the Unix file descriptor for reading and writing.
A type-safe version of WvMonikerBase that lets you provide create functions for object types other th...
WvUnixConn(int _fd, const WvUnixAddr &_addr)
connect an already-open socket (used by WvUnixListener)
virtual const WvUnixAddr * src() const
src() is a bit of a misnomer, but it returns the socket address.
WvString wvtcl_getword(WvBuf &buf, const WvStringMask &splitchars=WVTCL_SPLITCHARS, bool do_unescape=true)
Get a single tcl word from an input buffer, and return the rest of the buffer untouched.
virtual void close()
Closes the file descriptors.
IWvStream * accept()
return a new WvUnixConn socket corresponding to a newly-accepted connection.
Base class for streams built on Unix file descriptors.
Server end of a Unix Sockets stream.
void set_nonblock(bool nonblock)
Make the fds on this stream blocking or non-blocking.
virtual void seterr(int _errnum)
Override seterr() from WvError so that it auto-closes the stream.
virtual const WvUnixAddr * src() const
return the remote address (source of all incoming packets), which is a constant for any given connect...
void setcallback(IWvStreamCallback _callfunc)
define the callback function for this stream, called whenever the callback() member is run...
WvString is an implementation of a simple and efficient printable-string class.
virtual bool isok() const
By default, returns true if geterr() == 0.
WvStreamClone simply forwards all requests to the "cloned" stream.
virtual void addwrap(IWvListenerWrapper _wrapper)=0
Add a wrapper function for this stream: something that accept() will call to possibly wrap the stream...
WvStream-based Unix domain socket connection class.
WvStreamList holds a list of WvStream objects – and its select() and callback() functions know how t...