ns-3 Direct Code Execution
Home
Tutorials ▼
Docs ▼
Wiki
Manual
Develop ▼
API
Bugs
API
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
unix-timer-fd.cc
Go to the documentation of this file.
1
#include "
unix-timer-fd.h
"
2
#include "
utils.h
"
3
#include "
process.h
"
4
#include "
dce-manager.h
"
5
#include "ns3/log.h"
6
#include "ns3/simulator.h"
7
#include "
task-manager.h
"
8
#include <errno.h>
9
#include <sys/mman.h>
10
#include <poll.h>
11
12
NS_LOG_COMPONENT_DEFINE
(
"UnixTimerFd"
);
13
14
namespace
ns3 {
15
16
UnixTimerFd::UnixTimerFd
(
int
clockid,
int
flags)
17
: m_period (Seconds (0.0)),
18
m_skipped (0),
19
m_timer (),
20
m_waiter (0)
21
{
22
}
23
24
int
25
UnixTimerFd::Close
(
void
)
26
{
27
m_timer
.Cancel ();
28
if
(
m_waiter
!= 0)
29
{
30
m_waiter
->
process
->
manager
->
Wakeup
(
m_waiter
);
31
}
32
return
0;
33
}
34
35
ssize_t
36
UnixTimerFd::Write
(
const
void
*buf,
size_t
count)
37
{
38
NS_LOG_FUNCTION (
this
<< buf << count);
39
Thread
*current =
Current
();
40
current->
err
= EINVAL;
41
return
-1;
42
}
43
ssize_t
44
UnixTimerFd::Read
(
void
*buf,
size_t
count)
45
{
46
Thread
*current =
Current
();
47
if
(count < 8)
48
{
49
current->
err
= EINVAL;
50
return
-1;
51
}
52
uint64_t *counter = (uint64_t *)buf;
53
if
(
m_skipped
> 0)
54
{
55
*counter =
m_skipped
;
56
m_skipped
= 0;
57
return
0;
58
}
59
m_waiter
= current;
60
current->
process
->
manager
->
Wait
();
61
m_waiter
= 0;
62
*counter =
m_skipped
;
63
m_skipped
= 0;
64
65
return
0;
66
}
67
ssize_t
68
UnixTimerFd::Recvmsg
(
struct
msghdr *msg,
int
flags)
69
{
70
NS_LOG_FUNCTION (
this
<< msg << flags);
71
Thread
*current =
Current
();
72
current->
err
= ENOTSOCK;
73
return
-1;
74
}
75
ssize_t
76
UnixTimerFd::Sendmsg
(
const
struct
msghdr *msg,
int
flags)
77
{
78
NS_LOG_FUNCTION (
this
<< msg << flags);
79
Thread
*current =
Current
();
80
current->
err
= ENOTSOCK;
81
return
-1;
82
}
83
bool
84
UnixTimerFd::Isatty
(
void
)
const
85
{
86
return
false
;
87
}
88
int
89
UnixTimerFd::Setsockopt
(
int
level,
int
optname,
90
const
void
*optval, socklen_t optlen)
91
{
92
NS_LOG_FUNCTION (
this
<< level << optname << optval << optlen);
93
Thread
*current =
Current
();
94
current->
err
= ENOTSOCK;
95
return
-1;
96
}
97
int
98
UnixTimerFd::Getsockopt
(
int
level,
int
optname,
99
void
*optval, socklen_t *optlen)
100
{
101
NS_LOG_FUNCTION (
this
<< level << optname << optval << optlen);
102
Thread
*current =
Current
();
103
current->
err
= ENOTSOCK;
104
return
-1;
105
}
106
int
107
UnixTimerFd::Getsockname
(
struct
sockaddr *name, socklen_t *namelen)
108
{
109
NS_LOG_FUNCTION (
this
<< name << namelen);
110
Thread
*current =
Current
();
111
current->
err
= ENOTSOCK;
112
return
-1;
113
}
114
int
115
UnixTimerFd::Getpeername
(
struct
sockaddr *name, socklen_t *namelen)
116
{
117
NS_LOG_FUNCTION (
this
<< name << namelen);
118
Thread
*current =
Current
();
119
current->
err
= ENOTSOCK;
120
return
-1;
121
}
122
int
123
UnixTimerFd::Ioctl
(
int
request,
char
*argp)
124
{
125
//XXX
126
return
-1;
127
}
128
int
129
UnixTimerFd::Bind
(
const
struct
sockaddr *my_addr, socklen_t addrlen)
130
{
131
NS_LOG_FUNCTION (
this
<< my_addr << addrlen);
132
Thread
*current =
Current
();
133
current->
err
= ENOTSOCK;
134
return
-1;
135
}
136
int
137
UnixTimerFd::Connect
(
const
struct
sockaddr *my_addr, socklen_t addrlen)
138
{
139
NS_LOG_FUNCTION (
this
<< my_addr << addrlen);
140
Thread
*current =
Current
();
141
current->
err
= ENOTSOCK;
142
return
-1;
143
}
144
int
145
UnixTimerFd::Listen
(
int
backlog)
146
{
147
NS_LOG_FUNCTION (
this
<< backlog);
148
Thread
*current =
Current
();
149
current->
err
= ENOTSOCK;
150
return
-1;
151
}
152
int
153
UnixTimerFd::Shutdown
(
int
how)
154
{
155
NS_LOG_FUNCTION (
this
<< how);
156
Thread
*current =
Current
();
157
current->
err
= ENOTSOCK;
158
return
-1;
159
}
160
int
161
UnixTimerFd::Accept
(
struct
sockaddr *my_addr, socklen_t *addrlen)
162
{
163
NS_LOG_FUNCTION (
this
<< my_addr << addrlen);
164
Thread
*current =
Current
();
165
current->
err
= ENOTSOCK;
166
return
-1;
167
}
168
void
*
169
UnixTimerFd::Mmap
(
void
*start,
size_t
length,
int
prot,
int
flags, off64_t offset)
170
{
171
NS_LOG_FUNCTION (
this
<< start << length << prot << flags << offset);
172
Thread
*current =
Current
();
173
current->
err
= EINVAL;
174
return
MAP_FAILED;
175
}
176
off64_t
177
UnixTimerFd::Lseek
(off64_t offset,
int
whence)
178
{
179
NS_LOG_FUNCTION (
this
<< offset << whence);
180
Thread
*current =
Current
();
181
current->
err
= ESPIPE;
182
return
-1;
183
}
184
int
185
UnixTimerFd::Fxstat
(
int
ver, struct ::stat *buf)
186
{
187
NS_LOG_FUNCTION (
this
<< buf);
188
//XXX: I do not know what I should write here.
189
// but this call is expected to succeed by the kernel.
190
return
0;
191
}
192
int
193
UnixTimerFd::Fxstat64
(
int
ver, struct ::stat64 *buf)
194
{
195
NS_LOG_FUNCTION (
this
<< buf);
196
//XXX: I do not know what I should write here.
197
// but this call is expected to succeed by the kernel.
198
return
0;
199
}
200
int
201
UnixTimerFd::Fcntl
(
int
cmd,
unsigned
long
arg)
202
{
203
// XXX: this really needs to be fixed
204
return
0;
205
}
206
void
207
UnixTimerFd::TimerExpired
(
void
)
208
{
209
if
(!
m_period
.IsZero ())
210
{
211
m_timer
= Simulator::Schedule (
m_period
,
212
&
UnixTimerFd::TimerExpired
,
213
this
);
214
}
215
m_skipped
++;
216
if
(
m_waiter
!= 0)
217
{
218
m_waiter
->
process
->
manager
->
Wakeup
(
m_waiter
);
219
}
220
}
221
void
222
UnixTimerFd::SettimeMain
(Time t)
223
{
224
m_timer
= Simulator::Schedule (t,
225
&
UnixTimerFd::TimerExpired
,
226
this
);
227
}
228
int
229
UnixTimerFd::Settime
(
int
flags,
230
const
struct
itimerspec *new_value,
231
struct
itimerspec *old_value)
232
{
233
NS_ASSERT (flags == 0);
234
if
(old_value != 0)
235
{
236
Gettime
(old_value);
237
}
238
m_skipped
= 0;
239
m_timer
.Cancel ();
240
m_period
=
UtilsTimespecToTime
(new_value->it_interval);
241
Time initial =
UtilsTimespecToTime
(new_value->it_value);
242
if
(!initial.IsZero ())
243
{
244
TaskManager::Current
()->ExecOnMain (MakeEvent (&
UnixTimerFd::SettimeMain
,
245
this
, initial));
246
}
247
return
0;
248
}
249
int
250
UnixTimerFd::Gettime
(
struct
itimerspec *cur_value)
const
251
{
252
if
(!
m_timer
.IsRunning ())
253
{
254
cur_value->it_value.tv_sec = 0;
255
cur_value->it_value.tv_nsec = 0;
256
}
257
else
258
{
259
Time left = Simulator::GetDelayLeft (
m_timer
);
260
cur_value->it_value =
UtilsTimeToTimespec
(left);
261
}
262
cur_value->it_interval =
UtilsTimeToTimespec
(
m_period
);
263
return
0;
264
}
265
266
bool
267
UnixTimerFd::CanRecv
(
void
)
const
268
{
269
// XXX ?
270
return
false
;
271
}
272
bool
273
UnixTimerFd::CanSend
(
void
)
const
274
{
275
return
false
;
276
}
277
bool
278
UnixTimerFd::HangupReceived
(
void
)
const
279
{
280
return
false
;
281
}
282
int
283
UnixTimerFd::Poll
(
PollTable
* ptable)
284
{
285
int
ret = 0;
286
287
if
(
CanRecv
())
288
{
289
ret |= POLLIN;
290
}
291
if
(
CanSend
())
292
{
293
ret |= POLLOUT;
294
}
295
if
(
HangupReceived
())
296
{
297
ret |= POLLHUP;
298
}
299
300
if
(ptable)
301
{
302
ptable->
PollWait
(
this
);
303
}
304
305
return
ret;
306
}
307
308
int
309
UnixTimerFd::Ftruncate
(off_t length)
310
{
311
Thread
*current =
Current
();
312
NS_ASSERT (current != 0);
313
NS_LOG_FUNCTION (
this
<< current << length);
314
315
current->
err
= EINVAL;
316
return
-1;
317
}
318
319
}
// namespace ns3
model
unix-timer-fd.cc
Generated on Fri Aug 30 2013 13:57:56 for ns-3-dce by
1.8.1.2