diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | includes/StdIO.h | 40 | ||||
-rw-r--r-- | src/StdIO.cc | 72 |
3 files changed, 114 insertions, 0 deletions
@@ -51,6 +51,8 @@ Buffer.cc \ BStream.cc \ ZHandle.cc \ \ +StdIO.cc \ +\ Task.cc \ TaskMan.cc \ \ diff --git a/includes/StdIO.h b/includes/StdIO.h new file mode 100644 index 0000000..9b7e362 --- /dev/null +++ b/includes/StdIO.h @@ -0,0 +1,40 @@ +#pragma once + +#include <Handle.h> +#include <Selectable.h> + +namespace Balau { + +// these classes might very well need to have their own +// special version for win32; at least from a Handle. +class StdIN : public Selectable { + public: + StdIN(); + virtual const char * getName(); + virtual void close() throw (GeneralException); + private: + virtual ssize_t recv(int sockfd, void *buf, size_t len, int flags); + virtual ssize_t send(int sockfd, const void *buf, size_t len, int flags); +}; + +class StdOUT : public Selectable { + public: + StdOUT(); + virtual const char * getName(); + virtual void close() throw (GeneralException); + private: + virtual ssize_t recv(int sockfd, void *buf, size_t len, int flags); + virtual ssize_t send(int sockfd, const void *buf, size_t len, int flags); +}; + +class StdERR : public Selectable { + public: + StdERR(); + virtual const char * getName(); + virtual void close() throw (GeneralException); + private: + virtual ssize_t recv(int sockfd, void *buf, size_t len, int flags); + virtual ssize_t send(int sockfd, const void *buf, size_t len, int flags); +}; + +}; diff --git a/src/StdIO.cc b/src/StdIO.cc new file mode 100644 index 0000000..ccdeac2 --- /dev/null +++ b/src/StdIO.cc @@ -0,0 +1,72 @@ +#include "StdIO.h" + +/** stdin **/ +Balau::StdIN::StdIN() { + setFD(0); +} + +const char * Balau::StdIN::getName() { + return "stdin"; +} + +void Balau::StdIN::close() throw (GeneralException) { + ::close(0); + internalClose(); +} + +ssize_t Balau::StdIN::recv(int sockfd, void *buf, size_t len, int flags) { + IAssert(sockfd == 0, "StdIN::recv called, but not on stdin"); + + return ::read(0, buf, len); +} + +ssize_t Balau::StdIN::send(int sockfd, const void *buf, size_t len, int flags) { + return 0; +} + +/** stdout **/ +Balau::StdOUT::StdOUT() { + setFD(1); +} + +const char * Balau::StdOUT::getName() { + return "stdout"; +} + +void Balau::StdOUT::close() throw (GeneralException) { + ::close(1); + internalClose(); +} + +ssize_t Balau::StdOUT::recv(int sockfd, void *buf, size_t len, int flags) { + return 0; +} + +ssize_t Balau::StdOUT::send(int sockfd, const void *buf, size_t len, int flags) { + IAssert(sockfd == 1, "StdOUT::send called, but not on stdout"); + return ::write(1, buf, len); +} + +/** stderr **/ +Balau::StdERR::StdERR() { + setFD(2); +} + +const char * Balau::StdERR::getName() { + return "stderr"; +} + +void Balau::StdERR::close() throw (GeneralException) { + ::close(2); + internalClose(); +} + +ssize_t Balau::StdERR::recv(int sockfd, void *buf, size_t len, int flags) { + return 0; +} + +ssize_t Balau::StdERR::send(int sockfd, const void *buf, size_t len, int flags) { + IAssert(sockfd == 2, "StdERR::send called, but not on stderr"); + return ::write(2, buf, len); +} + |