summaryrefslogtreecommitdiff
path: root/vio/VioFd.cc
blob: da59798fc254fc18bd9211baba2d7bbae3682013 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/* 
**  Virtual I/O library for files
**  Written by Andrei Errapart <andreie@no.spam.ee>
**  Checked and modfied by Monty
*/

#include "vio-global.h"
#include <assert.h>

#ifdef __GNUC__
#pragma implementation				// gcc: Class implementation
#endif

VIO_NS_BEGIN

VioFd::VioFd(	int	fd) : fd_(fd)
{
  sprintf(desc_, "VioFd(%d)", fd_);
}

VioFd::	~VioFd()
{
  if (fd_ >= 0)
  {
    it r = ::close(fd_);
    if ( r < 0)
    {
      /* FIXME: error handling (Not Critical for MySQL)  */
    }
  }
}


bool
VioFd::open() const
{
  return fd_ >= 0;
}

int
VioFd::read(vio_ptr buf, int size)
{
  assert(fd_>=0);
  return ::read(fd_, buf, size);
}

int
VioFd::write(const vio_ptr buf,	int size)
{
  assert(fd_>=0);
  return ::write(fd_, buf, size);
}

int
VioFd::blocking(bool onoff)
{
  if (onoff)
    return 0;
  else
    return -1;
}

bool 
VioFd::blocking() const
{
  return true;
}

int
VioFd::fastsend(bool tmp)
{
  return 0;
}


int
VioFd::keepalive(boolonoff)
{
  return -2;					// Why -2 ? (monty)
}

bool
VioFd::fcntl() const
{
  return FALSE;
}

bool
VioFd::should_retry() const
{
  return FALSE;
}

int
VioFd::fcntl(int cmd)
{
  assert(fd_>=0);
  return ::fcntl(fd_, cmd);
}

int
VioFd::fcntl(int cmd, long arg)
{
  assert(fd_>=0);
  return ::fcntl(fd_, cmd, arg);
}

int
VioFd::fcntl(int cmd, struct flock* lock)
{
  assert(fd_>=0);
  return ::fcntl(fd_, cmd, lock);
}

int
VioFd::close()
{
  int	r = -2;
  if (fd_>=0)
  {
    
    if ((r= ::close(fd_)) == 0)
      fd_ = -1;
  }
  else
  {
    /* FIXME: error handling */
  }
  return r;
}

const char*
VioFd::description() const
{
  return desc_;
}

const char*
VioFd::peer_addr() const
{
  return "";
}

const char*
VioFd::peer_name() const
{
  return "localhost";
}

const char*
VioFd::cipher_description() const
{
  return "";
}

VIO_NS_END