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 class used to provide a masked lookup for characters in a string.
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 addwrap(IWvListenerWrapper _wrapper)=0
Add a wrapper function for this stream: something that accept() will call to possibly wrap the stream...
virtual void seterr(int _errnum)
Set the errnum variable – we have an error.
A raw memory read-only buffer backed by a constant WvString.
virtual void seterr(int _errnum)
Override seterr() from WvError so that it auto-closes the stream.
WvString is an implementation of a simple and efficient printable-string class.
void setfd(int fd)
Sets the file descriptor for both reading and writing.
A type-safe version of WvMonikerBase that lets you provide create functions for object types other th...
WvStreamClone simply forwards all requests to the "cloned" stream.
int getfd() const
Returns the Unix file descriptor for reading and writing.
void set_close_on_exec(bool close_on_exec)
Make the fds on this stream close-on-exec or not.
virtual const WvUnixAddr * src() const
return the remote address (source of all incoming packets), which is a constant for any given connect...
virtual void close()
Closes the file descriptors.
void setcallback(IWvStreamCallback _callfunc)
define the callback function for this stream, called whenever the callback() member is run,...
Server end of a Unix Sockets stream.
Base class for streams built on Unix file descriptors.
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.
WvStreamList holds a list of WvStream objects – and its select() and callback() functions know how to...
void set_nonblock(bool nonblock)
Make the fds on this stream blocking or non-blocking.
WvStream-based Unix domain socket connection class.
A Unix domain socket address is really just a filename.
IWvStream * accept()
return a new WvUnixConn socket corresponding to a newly-accepted connection.
virtual bool isok() const
By default, returns true if geterr() == 0.