7#include "wvistreamlist.h"
8#include "wvunixlistener.h"
9#include "wvunixsocket.h"
10#include "wvstringmask.h"
12#include "wvlinkerhack.h"
19# include <sys/types.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>
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)
130WvUnixConn::~WvUnixConn()
146WvUnixListener::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))
193WvUnixListener::~WvUnixListener()
199void 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");
The basic interface which is included by all other XPLC interfaces and objects.
virtual void addwrap(IWvListenerWrapper _wrapper)=0
Add a wrapper function for this stream: something that accept() will call to possibly wrap the stream...
A raw memory read-only buffer backed by a constant WvString.
virtual void seterr(int _errnum)
Set the errnum variable – we have an error.
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
Base class for streams built on Unix file descriptors.
void setfd(int fd)
Sets the file descriptor for both reading and writing.
int getfd() const
Returns the Unix file descriptor for reading and writing.
void set_nonblock(bool nonblock)
Make the fds on this stream blocking or non-blocking.
virtual void close()
Closes the file descriptors.
void set_close_on_exec(bool close_on_exec)
Make the fds on this stream close-on-exec or not.
WvStreamList holds a list of WvStream objects – and its select() and callback() functions know how to...
virtual bool isok() const
By default, returns true if geterr() == 0.
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.
void setcallback(IWvStreamCallback _callfunc)
define the callback function for this stream, called whenever the callback() member is run,...
virtual void seterr(int _errnum)
Override seterr() from WvError so that it auto-closes the stream.
A class used to provide a masked lookup for characters in a string.
WvString is an implementation of a simple and efficient printable-string class.
A Unix domain socket address is really just a filename.
WvStream-based Unix domain socket connection class.
WvUnixConn(int _fd, const WvUnixAddr &_addr)
connect an already-open socket (used by WvUnixListener)
virtual const WvUnixAddr * src() const
return the remote address (source of all incoming packets), which is a constant for any given connect...
Server end of a Unix Sockets stream.
virtual const WvUnixAddr * src() const
src() is a bit of a misnomer, but it returns the socket address.
IWvStream * accept()
return a new WvUnixConn socket corresponding to a newly-accepted connection.
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.