Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
Socket.cxx
Go to the documentation of this file.
1
34#include <cstdlib>
35#include <cstdint>
36#include <sys/socket.h>
37#include <sys/stat.h>
38
39#include "Devtab.hxx"
40#include "Socket.hxx"
41#include "can_ioctl.h"
42
50ssize_t Socket::read(File *file, void *buf, size_t count)
51{
52 ssize_t result = ::recv(fd_lookup(file), buf, count, 0);
53 if (result < 0)
54 {
55 return -errno;
56 }
57 return result;
58}
59
67ssize_t Socket::write(File *file, const void *buf, size_t count)
68{
69 ssize_t result = ::send(fd_lookup(file), buf, count, 0);
70 if (result < 0)
71 {
72 return -errno;
73 }
74 return result;
75}
76
83int Socket::ioctl(File *file, unsigned long int key, unsigned long data)
84{
85 return -1;
86}
87
94bool Socket::select(File *file, int mode)
95{
96 bool retval = false;
97
98 return retval;
99}
100
101extern "C"
102{
103int socket(int domain, int type, int protocol)
104 __attribute__ ((weak));
105
106int bind(int socket, const struct sockaddr *address, socklen_t address_len)
107 __attribute__ ((weak));
108
109int listen(int socket, int backlog)
110 __attribute__ ((weak));
111
112int accept(int socket, struct sockaddr *address, socklen_t *address_len)
113 __attribute__ ((weak));
114
115int connect(int socket, const struct sockaddr *address, socklen_t address_len)
116 __attribute__ ((weak));
117
118ssize_t recv(int socket, void *buffer, size_t length, int flags)
119 __attribute__ ((weak));
120
121ssize_t send(int socket, const void *buffer, size_t length, int flags)
122 __attribute__ ((weak));
123
124int setsockopt(int socket, int level, int option_name,
125 const void *option_value, socklen_t option_len)
126 __attribute__ ((weak));
127
128int getsockopt(int socket, int level, int option_name,
129 void *option_value, socklen_t *option_len)
130 __attribute__ ((weak));
131
144int socket(int domain, int type, int protocol)
145{
146 errno = EINVAL;
147 return -1;
148}
149
159int bind(int socket, const struct sockaddr *address, socklen_t address_len)
160{
161 errno = EINVAL;
162 return -1;
163}
164
174int listen(int socket, int backlog)
175{
176 errno = EINVAL;
177 return -1;
178}
179
194int accept(int socket, struct sockaddr *address, socklen_t *address_len)
195{
196 errno = EINVAL;
197 return -1;
198}
199
208int connect(int socket, const struct sockaddr *address, socklen_t address_len)
209{
210 errno = EINVAL;
211 return -1;
212}
213
225ssize_t recv(int socket, void *buffer, size_t length, int flags)
226{
227 errno = EINVAL;
228 return -1;
229}
230
239ssize_t send(int socket, const void *buffer, size_t length, int flags)
240{
241 errno = EINVAL;
242 return -1;
243}
244
255int setsockopt(int socket, int level, int option_name,
256 const void *option_value, socklen_t option_len)
257{
258 errno = EINVAL;
259 return -1;
260}
261
272int getsockopt(int socket, int level, int option_name,
273 void *option_value, socklen_t *option_len)
274{
275 errno = EINVAL;
276 return -1;
277}
278} /* extern "C" */
ssize_t recv(int socket, void *buffer, size_t length, int flags)
Receive a message from a connection-mode or connectionless-mode socket.
Definition Socket.cxx:225
int accept(int socket, struct sockaddr *address, socklen_t *address_len)
Accept a new connection on a socket.
Definition Socket.cxx:194
int setsockopt(int socket, int level, int option_name, const void *option_value, socklen_t option_len)
Set the socket options.
Definition Socket.cxx:255
int bind(int socket, const struct sockaddr *address, socklen_t address_len)
Bind a name to a socket.
Definition Socket.cxx:159
ssize_t send(int socket, const void *buffer, size_t length, int flags)
Initiate transmission of a message from the specified socket.
Definition Socket.cxx:239
int getsockopt(int socket, int level, int option_name, void *option_value, socklen_t *option_len)
Get the socket options.
Definition Socket.cxx:272
int listen(int socket, int backlog)
Mark a connection-mode socket, specified by the socket argument, as accepting connections.
Definition Socket.cxx:174
int connect(int socket, const struct sockaddr *address, socklen_t address_len)
Connect a socket.
Definition Socket.cxx:208
int socket(int domain, int type, int protocol)
Create an unbound socket in a communications domain.
Definition Socket.cxx:144
static int fd_lookup(File *file)
Looks up a file descriptor corresponding to a given File reference.
Definition Fileio.cxx:101
ssize_t write(File *file, const void *buf, size_t count) override
Write to a file or device.
Definition Socket.cxx:67
bool select(File *file, int mode) override
Device select method.
Definition Socket.cxx:94
int ioctl(File *file, unsigned long int key, unsigned long data) override
Request an ioctl transaction.
Definition Socket.cxx:83
ssize_t read(File *file, void *buf, size_t count) override
Read from a file or device.
Definition Socket.cxx:50
uint32_t socklen_t
type of sockaddr lenth
Definition socket.h:89
File information.
Definition Devtab.hxx:52
IPv4 socket address.
Definition socket.h:83