µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
os::posix::socket_implementable< T > Class Template Reference

#include <socket.h>

+ Inheritance diagram for os::posix::socket_implementable< T >:

Public Types

using value_type = T
 
Types & Constants
enum class  type : type_t {
  unknown = 0 ,
  not_set = 1 << 0 ,
  char_device = 1 << 1 ,
  block_device = 1 << 2 ,
  tty = 1 << 3 ,
  file = 1 << 4 ,
  socket = 1 << 5
}
 
using type_t = unsigned int
 

Public Member Functions

Constructors & Destructor
 socket_implementable (class net_stack &ns)
 
virtual ~socket_implementable ()
 
Public Member Functions
value_typeimpl (void) const
 
Public Member Functions
virtual socketaccept (sockaddr *address, socklen_t *address_len)
 
virtual int bind (const sockaddr *address, socklen_t address_len)
 
virtual int connect (const sockaddr *address, socklen_t address_len)
 
virtual int getpeername (sockaddr *address, socklen_t *address_len)
 
virtual int getsockname (sockaddr *address, socklen_t *address_len)
 
virtual int getsockopt (int level, int option_name, void *option_value, socklen_t *option_len)
 
virtual int listen (int backlog)
 
virtual ssize_t recv (void *buffer, size_t length, int flags)
 
virtual ssize_t recvfrom (void *buffer, size_t length, int flags, sockaddr *address, socklen_t *address_len)
 
virtual ssize_t recvmsg (msghdr *message, int flags)
 
virtual ssize_t send (const void *buffer, size_t length, int flags)
 
virtual ssize_t sendmsg (const msghdr *message, int flags)
 
virtual ssize_t sendto (const void *message, size_t length, int flags, const sockaddr *dest_addr, socklen_t dest_len)
 
virtual int setsockopt (int level, int option_name, const void *option_value, socklen_t option_len)
 
virtual int shutdown (int how)
 
virtual int sockatmark (void)
 
class net_stacknet_stack (void)
 
Public Member Functions
virtual int close (void)
 
virtual ssize_t read (void *buf, std::size_t nbyte)
 
virtual ssize_t write (const void *buf, std::size_t nbyte)
 
virtual ssize_t writev (const iovec *iov, int iovcnt)
 
int fcntl (int cmd,...)
 
virtual int vfcntl (int cmd, std::va_list args)
 
int isatty (void)
 
virtual int fstat (struct stat *buf)
 
virtual off_t lseek (off_t offset, int whence)
 
type_t get_type (void) const
 
file_descriptor_t file_descriptor (void) const
 
bool is_opened (void)
 

Protected Member Functions

Private Member Functions
void file_descriptor (file_descriptor_t fildes)
 
void clear_file_descriptor (void)
 
ioalloc_file_descriptor (void)
 

Detailed Description

template<typename T>
class os::posix::socket_implementable< T >

Definition at line 337 of file posix-io/socket.h.

Member Typedef Documentation

◆ type_t

using os::posix::io::type_t = unsigned int
inherited

Definition at line 125 of file io.h.

◆ value_type

template<typename T >
using os::posix::socket_implementable< T >::value_type = T

Definition at line 342 of file posix-io/socket.h.

Member Enumeration Documentation

◆ type

enum class os::posix::io::type : type_t
stronginherited
Enumerator
unknown 
not_set 
char_device 
block_device 
tty 
file 
socket 

Definition at line 126 of file io.h.

127 {
128 unknown = 0,
129 not_set = 1 << 0,
130 char_device = 1 << 1,
131 block_device = 1 << 2,
132 tty = 1 << 3,
133 file = 1 << 4,
134 socket = 1 << 5
135 };

Constructor & Destructor Documentation

◆ socket_implementable()

template<typename T >
os::posix::socket_implementable< T >::socket_implementable ( class net_stack ns)

Definition at line 572 of file posix-io/socket.h.

573 : socket{ impl_instance_, ns }
574 {
575#if defined(OS_TRACE_POSIX_IO_SOCKET)
576 trace::printf ("socket_implementable::%s()=@%p\n", __func__, this);
577#endif
578 }
socket(socket_impl &impl, net_stack &ns)
Definition socket.cpp:37
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:59

References os::trace::printf().

◆ ~socket_implementable()

template<typename T >
os::posix::socket_implementable< T >::~socket_implementable
virtual

Definition at line 581 of file posix-io/socket.h.

582 {
583#if defined(OS_TRACE_POSIX_IO_SOCKET)
584 trace::printf ("socket_implementable::%s() @%p\n", __func__, this);
585#endif
586 }

References os::trace::printf().

Member Function Documentation

◆ accept()

class socket * os::posix::socket::accept ( sockaddr address,
socklen_t address_len 
)
virtualinherited

Reimplemented in os::posix::socket_lockable< T, L >.

Definition at line 58 of file socket.cpp.

59 {
60 errno = 0;
61
62 // Execute the implementation specific code.
63 class socket* new_socket = impl ().do_accept (address, address_len);
64 if (new_socket == nullptr)
65 {
66 return nullptr;
67 }
68 new_socket->alloc_file_descriptor ();
69 return new_socket;
70 }
io * alloc_file_descriptor(void)
Definition io.cpp:189
virtual socket * do_accept(sockaddr *address, socklen_t *address_len)=0
socket_impl & impl(void) const

References os::posix::io::alloc_file_descriptor(), os::posix::socket_impl::do_accept(), and os::posix::socket::impl().

Referenced by os::posix::socket_lockable< T, L >::accept().

◆ alloc_file_descriptor()

io * os::posix::io::alloc_file_descriptor ( void  )
protectedinherited

Definition at line 189 of file io.cpp.

190 {
191#if defined(OS_TRACE_POSIX_IO_IO)
192 trace::printf ("io::%s() @%p\n", __func__, this);
193#endif
194
196 if (fd < 0)
197 {
198 // If allocation failed, close this object.
199 impl ().do_close ();
201 return nullptr;
202 }
203
204#if defined(OS_TRACE_POSIX_IO_IO)
205 trace::printf ("io::%s() @%p fd=%d\n", __func__, this, fd);
206#endif
207
208 // Return a valid pointer to an object derived from `io`.
209 return this;
210 }
virtual int do_close(void)=0
io_impl & impl(void) const
Definition io.h:464
void clear_file_descriptor(void)
Definition io.h:446

References os::posix::file_descriptors_manager::allocate(), os::posix::io::clear_file_descriptor(), os::posix::io_impl::do_close(), os::posix::io::impl(), and os::trace::printf().

Referenced by os::posix::socket::accept(), os::posix::socket(), os::posix::device::vopen(), and os::posix::file_system::vopen().

◆ bind()

int os::posix::socket::bind ( const sockaddr address,
socklen_t  address_len 
)
virtualinherited

Reimplemented in os::posix::socket_lockable< T, L >.

Definition at line 73 of file socket.cpp.

74 {
75 errno = 0;
76
77 // Execute the implementation specific code.
78 return impl ().do_bind (address, address_len);
79 }
virtual int do_bind(const sockaddr *address, socklen_t address_len)=0

References os::posix::socket_impl::do_bind(), and os::posix::socket::impl().

Referenced by os::posix::socket_lockable< T, L >::bind().

◆ clear_file_descriptor()

void os::posix::io::clear_file_descriptor ( void  )
inlineprotectedinherited

Definition at line 446 of file io.h.

447 {
448 file_descriptor_ = no_file_descriptor;
449 }
constexpr file_descriptor_t no_file_descriptor
Definition types.h:44

References os::posix::no_file_descriptor.

Referenced by os::posix::io::alloc_file_descriptor().

◆ close()

int os::posix::io::close ( void  )
virtualinherited

Reimplemented in os::posix::block_device_lockable< T, L >, os::posix::device, os::posix::file, os::posix::file_lockable< T, L >, and os::posix::socket_lockable< T, L >.

Definition at line 164 of file io.cpp.

165 {
166#if defined(OS_TRACE_POSIX_IO_IO)
167 trace::printf ("io::%s() @%p\n", __func__, this);
168#endif
169
170 if (!impl ().do_is_opened ())
171 {
172 errno = EBADF; // Not opened.
173 return -1;
174 }
175
176 errno = 0;
177
178 // Execute the implementation specific code.
179 int ret = impl ().do_close ();
180
181 // Remove this IO from the file descriptors registry.
182 file_descriptors_manager::deallocate (file_descriptor_);
183 file_descriptor_ = no_file_descriptor;
184
185 return ret;
186 }
static int deallocate(file_descriptor_t fildes)

References os::posix::file_descriptors_manager::deallocate(), os::posix::io_impl::do_close(), os::posix::io::impl(), os::posix::no_file_descriptor, and os::trace::printf().

Referenced by os::posix::device::close(), os::posix::file::close(), and os::posix::socket_lockable< T, L >::close().

◆ connect()

int os::posix::socket::connect ( const sockaddr address,
socklen_t  address_len 
)
virtualinherited

Reimplemented in os::posix::socket_lockable< T, L >.

Definition at line 82 of file socket.cpp.

84 {
85 errno = 0;
86
87 // Execute the implementation specific code.
88 return impl ().do_connect (address, address_len);
89 }
virtual int do_connect(const sockaddr *address, socklen_t address_len)=0

References os::posix::socket_impl::do_connect(), and os::posix::socket::impl().

Referenced by os::posix::socket_lockable< T, L >::connect().

◆ fcntl()

int os::posix::io::fcntl ( int  cmd,
  ... 
)
inherited

Definition at line 363 of file io.cpp.

364 {
365 // Forward to the variadic version of the function.
366 std::va_list args;
367 va_start (args, cmd);
368 int ret = vfcntl (cmd, args);
369 va_end (args);
370
371 return ret;
372 }
virtual int vfcntl(int cmd, std::va_list args)
Definition io.cpp:380

References os::posix::io::vfcntl().

◆ file_descriptor() [1/2]

void os::posix::io::file_descriptor ( file_descriptor_t  fildes)
inlineprotectedinherited

Definition at line 440 of file io.h.

441 {
442 file_descriptor_ = fildes;
443 }

◆ file_descriptor() [2/2]

file_descriptor_t os::posix::io::file_descriptor ( void  ) const
inlineinherited

Definition at line 452 of file io.h.

453 {
454 return file_descriptor_;
455 }

Referenced by os::posix::file_descriptors_manager::allocate(), os::posix::file_descriptors_manager::assign(), os::posix::device::vopen(), and os::posix::vopen().

◆ fstat()

int os::posix::io::fstat ( struct stat buf)
virtualinherited

Reimplemented in os::posix::file_lockable< T, L >.

Definition at line 416 of file io.cpp.

417 {
418#if defined(OS_TRACE_POSIX_IO_IO)
419 trace::printf ("io::%s(%p) @%p\n", __func__, buf, this);
420#endif
421
422 if (buf == nullptr)
423 {
424 errno = EFAULT;
425 return -1;
426 }
427
428 if (!impl ().do_is_opened ())
429 {
430 errno = EBADF; // Not opened.
431 return -1;
432 }
433
434 if (!impl ().do_is_connected ())
435 {
436 errno = EIO; // Not opened.
437 return -1;
438 }
439
440 errno = 0;
441
442 // Execute the implementation specific code.
443 return impl ().do_fstat (buf);
444 }
virtual int do_fstat(struct stat *buf)
Definition io.cpp:539

References os::posix::io_impl::do_fstat(), os::posix::io::impl(), and os::trace::printf().

Referenced by os::posix::file_lockable< T, L >::fstat().

◆ get_type()

io::type_t os::posix::io::get_type ( void  ) const
inlineinherited

Definition at line 434 of file io.h.

435 {
436 return type_;
437 }

Referenced by os::posix::file_descriptors_manager::socket().

◆ getpeername()

int os::posix::socket::getpeername ( sockaddr address,
socklen_t address_len 
)
virtualinherited

Reimplemented in os::posix::socket_lockable< T, L >.

Definition at line 92 of file socket.cpp.

94 {
95 errno = 0;
96
97 // Execute the implementation specific code.
98 return impl ().do_getpeername (address, address_len);
99 }
virtual int do_getpeername(sockaddr *address, socklen_t *address_len)=0

References os::posix::socket_impl::do_getpeername(), and os::posix::socket::impl().

Referenced by os::posix::socket_lockable< T, L >::getpeername().

◆ getsockname()

int os::posix::socket::getsockname ( sockaddr address,
socklen_t address_len 
)
virtualinherited

Reimplemented in os::posix::socket_lockable< T, L >.

Definition at line 102 of file socket.cpp.

104 {
105 errno = 0;
106
107 // Execute the implementation specific code.
108 return impl ().do_getsockname (address, address_len);
109 }
virtual int do_getsockname(sockaddr *address, socklen_t *address_len)=0

References os::posix::socket_impl::do_getsockname(), and os::posix::socket::impl().

Referenced by os::posix::socket_lockable< T, L >::getsockname().

◆ getsockopt()

int os::posix::socket::getsockopt ( int  level,
int  option_name,
void *  option_value,
socklen_t option_len 
)
virtualinherited

Reimplemented in os::posix::socket_lockable< T, L >.

Definition at line 112 of file socket.cpp.

114 {
115 errno = 0;
116
117 // Execute the implementation specific code.
118 return impl ().do_getsockopt (level, option_name, option_value,
119 option_len);
120 }
virtual int do_getsockopt(int level, int option_name, void *option_value, socklen_t *option_len)=0

References os::posix::socket_impl::do_getsockopt(), and os::posix::socket::impl().

Referenced by os::posix::socket_lockable< T, L >::getsockopt().

◆ impl()

template<typename T >
socket_implementable< T >::value_type & os::posix::socket_implementable< T >::impl ( void  ) const

Definition at line 590 of file posix-io/socket.h.

591 {
592 return static_cast<value_type&> (impl_);
593 }

◆ is_opened()

bool os::posix::io::is_opened ( void  )
inlineinherited

Definition at line 458 of file io.h.

459 {
460 return impl ().do_is_opened ();
461 }
virtual bool do_is_opened(void)=0

References os::posix::io_impl::do_is_opened(), and os::posix::io::impl().

◆ isatty()

int os::posix::io::isatty ( void  )
inherited

Definition at line 406 of file io.cpp.

407 {
408 errno = 0;
409
410 // Execute the implementation specific code.
411 return impl ().do_isatty ();
412 }
virtual int do_isatty(void)
Definition io.cpp:532

References os::posix::io_impl::do_isatty(), and os::posix::io::impl().

◆ listen()

int os::posix::socket::listen ( int  backlog)
virtualinherited

Reimplemented in os::posix::socket_lockable< T, L >.

Definition at line 123 of file socket.cpp.

124 {
125 errno = 0;
126
127 // Execute the implementation specific code.
128 return impl ().do_listen (backlog);
129 }
virtual int do_listen(int backlog)=0

References os::posix::socket_impl::do_listen(), and os::posix::socket::impl().

Referenced by os::posix::socket_lockable< T, L >::listen().

◆ lseek()

off_t os::posix::io::lseek ( off_t  offset,
int  whence 
)
virtualinherited

Reimplemented in os::posix::block_device_lockable< T, L >, and os::posix::file_lockable< T, L >.

Definition at line 447 of file io.cpp.

448 {
449#if defined(OS_TRACE_POSIX_IO_IO)
450 trace::printf ("io::%s(%d, %d) @%p\n", __func__, offset, whence, this);
451#endif
452
453 if (!impl ().do_is_opened ())
454 {
455 errno = EBADF; // Not opened.
456 return -1;
457 }
458
459 errno = 0;
460
461 // Execute the implementation specific code.
462 return impl ().do_lseek (offset, whence);
463 }
virtual off_t do_lseek(off_t offset, int whence)=0

References os::posix::io_impl::do_lseek(), os::posix::io::impl(), and os::trace::printf().

Referenced by os::posix::block_device_lockable< T, L >::lseek(), and os::posix::file_lockable< T, L >::lseek().

◆ net_stack()

net_stack * os::posix::socket::net_stack ( void  )
inlineinherited

Definition at line 558 of file posix-io/socket.h.

559 {
560 return net_stack_;
561 }

◆ read()

ssize_t os::posix::io::read ( void *  buf,
std::size_t  nbyte 
)
virtualinherited

Reimplemented in os::posix::block_device_lockable< T, L >, and os::posix::file_lockable< T, L >.

Definition at line 217 of file io.cpp.

218 {
219#if defined(OS_TRACE_POSIX_IO_IO)
220 trace::printf ("io::%s(0x0%X, %u) @%p\n", __func__, buf, nbyte, this);
221#endif
222
223 if (buf == nullptr)
224 {
225 errno = EFAULT;
226 return -1;
227 }
228
229 if (!impl ().do_is_opened ())
230 {
231 errno = EBADF; // Not opened.
232 return -1;
233 }
234
235 if (!impl ().do_is_connected ())
236 {
237 errno = EIO; // Not opened.
238 return -1;
239 }
240
241 errno = 0;
242
243 // http://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html
244 // Before any action described below is taken, and if nbyte is zero,
245 // the read() function may detect and return errors as described below.
246 // In the absence of errors, or if error detection is not performed,
247 // the read() function shall return zero and have no other results.
248 if (nbyte == 0)
249 {
250 return 0; // Nothing to do.
251 }
252
253 // Execute the implementation specific code.
254 ssize_t ret = impl ().do_read (buf, nbyte);
255 if (ret >= 0)
256 {
257 impl ().offset_ += ret;
258 }
259
260#if defined(OS_TRACE_POSIX_IO_IO)
261 trace::printf ("io::%s(0x0%X, %u) @%p n=%d\n", __func__, buf, nbyte,
262 this, ret);
263#endif
264 return ret;
265 }
virtual ssize_t do_read(void *buf, std::size_t nbyte)=0

References os::posix::io_impl::do_read(), os::posix::io::impl(), and os::trace::printf().

Referenced by os::posix::block_device_lockable< T, L >::read(), and os::posix::file_lockable< T, L >::read().

◆ recv()

ssize_t os::posix::socket::recv ( void *  buffer,
size_t  length,
int  flags 
)
virtualinherited

Reimplemented in os::posix::socket_lockable< T, L >.

Definition at line 132 of file socket.cpp.

133 {
134 errno = 0;
135
136 // Execute the implementation specific code.
137 return impl ().do_recv (buffer, length, flags);
138 }
virtual ssize_t do_recv(void *buffer, size_t length, int flags)=0

References os::posix::socket_impl::do_recv(), and os::posix::socket::impl().

Referenced by os::posix::socket_lockable< T, L >::recv().

◆ recvfrom()

ssize_t os::posix::socket::recvfrom ( void *  buffer,
size_t  length,
int  flags,
sockaddr address,
socklen_t address_len 
)
virtualinherited

Reimplemented in os::posix::socket_lockable< T, L >.

Definition at line 141 of file socket.cpp.

143 {
144 errno = 0;
145
146 // Execute the implementation specific code.
147 return impl ().do_recvfrom (buffer, length, flags, address, address_len);
148 }
virtual ssize_t do_recvfrom(void *buffer, size_t length, int flags, sockaddr *address, socklen_t *address_len)=0

References os::posix::socket_impl::do_recvfrom(), and os::posix::socket::impl().

Referenced by os::posix::socket_lockable< T, L >::recvfrom().

◆ recvmsg()

ssize_t os::posix::socket::recvmsg ( msghdr *  message,
int  flags 
)
virtualinherited

Reimplemented in os::posix::socket_lockable< T, L >.

Definition at line 151 of file socket.cpp.

152 {
153 errno = 0;
154
155 // Execute the implementation specific code.
156 return impl ().do_recvmsg (message, flags);
157 }
virtual ssize_t do_recvmsg(msghdr *message, int flags)=0

References os::posix::socket_impl::do_recvmsg(), and os::posix::socket::impl().

Referenced by os::posix::socket_lockable< T, L >::recvmsg().

◆ send()

ssize_t os::posix::socket::send ( const void *  buffer,
size_t  length,
int  flags 
)
virtualinherited

Reimplemented in os::posix::socket_lockable< T, L >.

Definition at line 160 of file socket.cpp.

161 {
162 errno = 0;
163
164 // Execute the implementation specific code.
165 return impl ().do_send (buffer, length, flags);
166 }
virtual ssize_t do_send(const void *buffer, size_t length, int flags)=0

References os::posix::socket_impl::do_send(), and os::posix::socket::impl().

Referenced by os::posix::socket_lockable< T, L >::send().

◆ sendmsg()

ssize_t os::posix::socket::sendmsg ( const msghdr *  message,
int  flags 
)
virtualinherited

Reimplemented in os::posix::socket_lockable< T, L >.

Definition at line 169 of file socket.cpp.

170 {
171 errno = 0;
172
173 // Execute the implementation specific code.
174 return impl ().do_sendmsg (message, flags);
175 }
virtual ssize_t do_sendmsg(const msghdr *message, int flags)=0

References os::posix::socket_impl::do_sendmsg(), and os::posix::socket::impl().

Referenced by os::posix::socket_lockable< T, L >::sendmsg().

◆ sendto()

ssize_t os::posix::socket::sendto ( const void *  message,
size_t  length,
int  flags,
const sockaddr dest_addr,
socklen_t  dest_len 
)
virtualinherited

Reimplemented in os::posix::socket_lockable< T, L >.

Definition at line 178 of file socket.cpp.

180 {
181 errno = 0;
182
183 // Execute the implementation specific code.
184 return impl ().do_sendto (message, length, flags, dest_addr, dest_len);
185 }
virtual ssize_t do_sendto(const void *message, size_t length, int flags, const sockaddr *dest_addr, socklen_t dest_len)=0

References os::posix::socket_impl::do_sendto(), and os::posix::socket::impl().

Referenced by os::posix::socket_lockable< T, L >::sendto().

◆ setsockopt()

int os::posix::socket::setsockopt ( int  level,
int  option_name,
const void *  option_value,
socklen_t  option_len 
)
virtualinherited

Reimplemented in os::posix::socket_lockable< T, L >.

Definition at line 188 of file socket.cpp.

190 {
191 errno = 0;
192
193 // Execute the implementation specific code.
194 return impl ().do_setsockopt (level, option_name, option_value,
195 option_len);
196 }
virtual int do_setsockopt(int level, int option_name, const void *option_value, socklen_t option_len)=0

References os::posix::socket_impl::do_setsockopt(), and os::posix::socket::impl().

Referenced by os::posix::socket_lockable< T, L >::setsockopt().

◆ shutdown()

int os::posix::socket::shutdown ( int  how)
virtualinherited

Reimplemented in os::posix::socket_lockable< T, L >.

Definition at line 199 of file socket.cpp.

200 {
201 errno = 0;
202
203 // Execute the implementation specific code.
204 return impl ().do_shutdown (how);
205 }
virtual int do_shutdown(int how)=0

References os::posix::socket_impl::do_shutdown(), and os::posix::socket::impl().

Referenced by os::posix::socket_lockable< T, L >::shutdown().

◆ sockatmark()

int os::posix::socket::sockatmark ( void  )
virtualinherited

Reimplemented in os::posix::socket_lockable< T, L >.

Definition at line 208 of file socket.cpp.

209 {
210 errno = 0;
211
212 // Execute the implementation specific code.
213 return impl ().do_sockatmark ();
214 }
virtual int do_sockatmark(void)=0

References os::posix::socket_impl::do_sockatmark(), and os::posix::socket::impl().

Referenced by os::posix::socket_lockable< T, L >::sockatmark().

◆ vfcntl()

int os::posix::io::vfcntl ( int  cmd,
std::va_list  args 
)
virtualinherited

Reimplemented in os::posix::block_device_lockable< T, L >, and os::posix::file_lockable< T, L >.

Definition at line 380 of file io.cpp.

381 {
382#if defined(OS_TRACE_POSIX_IO_IO)
383 trace::printf ("io::%s(%d) @%p\n", __func__, cmd, this);
384#endif
385
386 if (!impl ().do_is_opened ())
387 {
388 errno = EBADF; // Not opened.
389 return -1;
390 }
391
392 if (!impl ().do_is_connected ())
393 {
394 errno = EIO; // Not opened.
395 return -1;
396 }
397
398 errno = 0;
399
400 // Execute the implementation specific code.
401 return impl ().do_vfcntl (cmd, args);
402 }
virtual int do_vfcntl(int cmd, std::va_list args)
Definition io.cpp:525

References os::posix::io_impl::do_vfcntl(), os::posix::io::impl(), and os::trace::printf().

Referenced by os::posix::io::fcntl(), os::posix::block_device_lockable< T, L >::vfcntl(), and os::posix::file_lockable< T, L >::vfcntl().

◆ write()

ssize_t os::posix::io::write ( const void *  buf,
std::size_t  nbyte 
)
virtualinherited

Reimplemented in os::posix::block_device_lockable< T, L >, and os::posix::file_lockable< T, L >.

Definition at line 268 of file io.cpp.

269 {
270#if defined(OS_TRACE_POSIX_IO_IO)
271 trace::printf ("io::%s(0x0%X, %u) @%p\n", __func__, buf, nbyte, this);
272#endif
273
274 if (buf == nullptr)
275 {
276 errno = EFAULT;
277 return -1;
278 }
279
280 if (!impl ().do_is_opened ())
281 {
282 errno = EBADF; // Not opened.
283 return -1;
284 }
285
286 if (!impl ().do_is_connected ())
287 {
288 errno = EIO; // Not opened.
289 return -1;
290 }
291
292 errno = 0;
293
294 // http://pubs.opengroup.org/onlinepubs/9699919799/functions/pwrite.html
295 // Before any action described below is taken, and if nbyte is zero
296 // and the file is a regular file, the write() function may detect and
297 // return errors as described below. In the absence of errors, or if
298 // error detection is not performed, the write() function shall return
299 // zero and have no other results. If nbyte is zero and the file is
300 // not a regular file, the results are unspecified.
301 if (nbyte == 0)
302 {
303 return 0; // Nothing to do.
304 }
305
306 // Execute the implementation specific code.
307 ssize_t ret = impl ().do_write (buf, nbyte);
308 if (ret >= 0)
309 {
310 impl ().offset_ += ret;
311 }
312
313#if defined(OS_TRACE_POSIX_IO_IO)
314 trace::printf ("io::%s(0x0%X, %u) @%p n=%d\n", __func__, buf, nbyte,
315 this, ret);
316#endif
317 return ret;
318 }
virtual ssize_t do_write(const void *buf, std::size_t nbyte)=0

References os::posix::io_impl::do_write(), os::posix::io::impl(), and os::trace::printf().

Referenced by os::posix::block_device_lockable< T, L >::write(), and os::posix::file_lockable< T, L >::write().

◆ writev()

ssize_t os::posix::io::writev ( const iovec iov,
int  iovcnt 
)
virtualinherited

Reimplemented in os::posix::block_device_lockable< T, L >, and os::posix::file_lockable< T, L >.

Definition at line 321 of file io.cpp.

322 {
323#if defined(OS_TRACE_POSIX_IO_IO)
324 trace::printf ("io::%s(0x0%X, %d) @%p\n", __func__, iov, iovcnt, this);
325#endif
326
327 if (iov == nullptr)
328 {
329 errno = EFAULT;
330 return -1;
331 }
332
333 if (iovcnt <= 0)
334 {
335 errno = EINVAL;
336 return -1;
337 }
338
339 if (!impl ().do_is_opened ())
340 {
341 errno = EBADF; // Not opened.
342 return -1;
343 }
344
345 if (!impl ().do_is_connected ())
346 {
347 errno = EIO; // Not opened.
348 return -1;
349 }
350
351 errno = 0;
352
353 // Execute the implementation specific code.
354 ssize_t ret = impl ().do_writev (iov, iovcnt);
355 if (ret >= 0)
356 {
357 impl ().offset_ += ret;
358 }
359 return ret;
360 }
virtual ssize_t do_writev(const iovec *iov, int iovcnt)
Definition io.cpp:502

References os::posix::io_impl::do_writev(), os::posix::io::impl(), and os::trace::printf().

Referenced by os::posix::block_device_lockable< T, L >::writev(), and os::posix::file_lockable< T, L >::writev().


The documentation for this class was generated from the following file: