summaryrefslogtreecommitdiff
path: root/src/StdIO.cc
blob: 24fa87debb1393558cedcf4983cdaff74bc14cc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "BStdIO.h"
#include <unistd.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);
}