@@ -33,10 +33,8 @@ namespace descriptor_ops {
33
33
34
34
int open (const char * path, int flags, boost::system::error_code& ec)
35
35
{
36
- errno = 0 ;
37
- int result = error_wrapper (::open (path, flags), ec);
38
- if (result >= 0 )
39
- ec = boost::system::error_code ();
36
+ int result = ::open (path, flags);
37
+ get_last_error (ec, result < 0 );
40
38
return result;
41
39
}
42
40
@@ -45,8 +43,8 @@ int close(int d, state_type& state, boost::system::error_code& ec)
45
43
int result = 0 ;
46
44
if (d != -1 )
47
45
{
48
- errno = 0 ;
49
- result = error_wrapper (:: close (d), ec );
46
+ result = :: close (d) ;
47
+ get_last_error (ec, result < 0 );
50
48
51
49
if (result != 0
52
50
&& (ec == boost::asio::error::would_block
@@ -68,13 +66,11 @@ int close(int d, state_type& state, boost::system::error_code& ec)
68
66
#endif // defined(__SYMBIAN32__) || defined(__EMSCRIPTEN__)
69
67
state &= ~non_blocking;
70
68
71
- errno = 0 ;
72
- result = error_wrapper (:: close (d), ec );
69
+ result = :: close (d) ;
70
+ get_last_error (ec, result < 0 );
73
71
}
74
72
}
75
73
76
- if (result == 0 )
77
- ec = boost::system::error_code ();
78
74
return result;
79
75
}
80
76
@@ -87,23 +83,23 @@ bool set_user_non_blocking(int d, state_type& state,
87
83
return false ;
88
84
}
89
85
90
- errno = 0 ;
91
86
#if defined(__SYMBIAN32__) || defined(__EMSCRIPTEN__)
92
- int result = error_wrapper (::fcntl (d, F_GETFL, 0 ), ec);
87
+ int result = ::fcntl (d, F_GETFL, 0 );
88
+ get_last_error (ec, result < 0 );
93
89
if (result >= 0 )
94
90
{
95
- errno = 0 ;
96
91
int flag = (value ? (result | O_NONBLOCK) : (result & ~O_NONBLOCK));
97
- result = error_wrapper (::fcntl (d, F_SETFL, flag), ec);
92
+ result = ::fcntl (d, F_SETFL, flag);
93
+ get_last_error (ec, result < 0 );
98
94
}
99
95
#else // defined(__SYMBIAN32__) || defined(__EMSCRIPTEN__)
100
96
ioctl_arg_type arg = (value ? 1 : 0 );
101
- int result = error_wrapper (::ioctl (d, FIONBIO, &arg), ec);
97
+ int result = ::ioctl (d, FIONBIO, &arg);
98
+ get_last_error (ec, result < 0 );
102
99
#endif // defined(__SYMBIAN32__) || defined(__EMSCRIPTEN__)
103
100
104
101
if (result >= 0 )
105
102
{
106
- ec = boost::system::error_code ();
107
103
if (value)
108
104
state |= user_set_non_blocking;
109
105
else
@@ -137,23 +133,23 @@ bool set_internal_non_blocking(int d, state_type& state,
137
133
return false ;
138
134
}
139
135
140
- errno = 0 ;
141
136
#if defined(__SYMBIAN32__) || defined(__EMSCRIPTEN__)
142
- int result = error_wrapper (::fcntl (d, F_GETFL, 0 ), ec);
137
+ int result = ::fcntl (d, F_GETFL, 0 );
138
+ get_last_error (ec, result < 0 );
143
139
if (result >= 0 )
144
140
{
145
- errno = 0 ;
146
141
int flag = (value ? (result | O_NONBLOCK) : (result & ~O_NONBLOCK));
147
- result = error_wrapper (::fcntl (d, F_SETFL, flag), ec);
142
+ result = ::fcntl (d, F_SETFL, flag);
143
+ get_last_error (ec, result < 0 );
148
144
}
149
145
#else // defined(__SYMBIAN32__) || defined(__EMSCRIPTEN__)
150
146
ioctl_arg_type arg = (value ? 1 : 0 );
151
- int result = error_wrapper (::ioctl (d, FIONBIO, &arg), ec);
147
+ int result = ::ioctl (d, FIONBIO, &arg);
148
+ get_last_error (ec, result < 0 );
152
149
#endif // defined(__SYMBIAN32__) || defined(__EMSCRIPTEN__)
153
150
154
151
if (result >= 0 )
155
152
{
156
- ec = boost::system::error_code ();
157
153
if (value)
158
154
state |= internal_non_blocking;
159
155
else
@@ -184,9 +180,8 @@ std::size_t sync_read(int d, state_type state, buf* bufs,
184
180
for (;;)
185
181
{
186
182
// Try to complete the operation without blocking.
187
- errno = 0 ;
188
- signed_size_type bytes = error_wrapper (::readv (
189
- d, bufs, static_cast <int >(count)), ec);
183
+ signed_size_type bytes = ::readv (d, bufs, static_cast <int >(count));
184
+ get_last_error (ec, bytes < 0 );
190
185
191
186
// Check if operation succeeded.
192
187
if (bytes > 0 )
@@ -217,9 +212,8 @@ bool non_blocking_read(int d, buf* bufs, std::size_t count,
217
212
for (;;)
218
213
{
219
214
// Read some data.
220
- errno = 0 ;
221
- signed_size_type bytes = error_wrapper (::readv (
222
- d, bufs, static_cast <int >(count)), ec);
215
+ signed_size_type bytes = ::readv (d, bufs, static_cast <int >(count));
216
+ get_last_error (ec, bytes < 0 );
223
217
224
218
// Check for end of stream.
225
219
if (bytes == 0 )
@@ -270,9 +264,8 @@ std::size_t sync_write(int d, state_type state, const buf* bufs,
270
264
for (;;)
271
265
{
272
266
// Try to complete the operation without blocking.
273
- errno = 0 ;
274
- signed_size_type bytes = error_wrapper (::writev (
275
- d, bufs, static_cast <int >(count)), ec);
267
+ signed_size_type bytes = ::writev (d, bufs, static_cast <int >(count));
268
+ get_last_error (ec, bytes < 0 );
276
269
277
270
// Check if operation succeeded.
278
271
if (bytes > 0 )
@@ -296,9 +289,8 @@ bool non_blocking_write(int d, const buf* bufs, std::size_t count,
296
289
for (;;)
297
290
{
298
291
// Write some data.
299
- errno = 0 ;
300
- signed_size_type bytes = error_wrapper (::writev (
301
- d, bufs, static_cast <int >(count)), ec);
292
+ signed_size_type bytes = ::writev (d, bufs, static_cast <int >(count));
293
+ get_last_error (ec, bytes < 0 );
302
294
303
295
// Retry operation if interrupted by signal.
304
296
if (ec == boost::asio::error::interrupted)
@@ -331,13 +323,11 @@ int ioctl(int d, state_type& state, long cmd,
331
323
return -1 ;
332
324
}
333
325
334
- errno = 0 ;
335
- int result = error_wrapper (:: ioctl (d, cmd, arg), ec );
326
+ int result = :: ioctl (d, cmd, arg) ;
327
+ get_last_error (ec, result < 0 );
336
328
337
329
if (result >= 0 )
338
330
{
339
- ec = boost::system::error_code ();
340
-
341
331
// When updating the non-blocking mode we always perform the ioctl syscall,
342
332
// even if the flags would otherwise indicate that the descriptor is
343
333
// already in the correct state. This ensures that the underlying
@@ -371,10 +361,8 @@ int fcntl(int d, int cmd, boost::system::error_code& ec)
371
361
return -1 ;
372
362
}
373
363
374
- errno = 0 ;
375
- int result = error_wrapper (::fcntl (d, cmd), ec);
376
- if (result != -1 )
377
- ec = boost::system::error_code ();
364
+ int result = ::fcntl (d, cmd);
365
+ get_last_error (ec, result < 0 );
378
366
return result;
379
367
}
380
368
@@ -386,10 +374,8 @@ int fcntl(int d, int cmd, long arg, boost::system::error_code& ec)
386
374
return -1 ;
387
375
}
388
376
389
- errno = 0 ;
390
- int result = error_wrapper (::fcntl (d, cmd, arg), ec);
391
- if (result != -1 )
392
- ec = boost::system::error_code ();
377
+ int result = ::fcntl (d, cmd, arg);
378
+ get_last_error (ec, result < 0 );
393
379
return result;
394
380
}
395
381
@@ -406,13 +392,11 @@ int poll_read(int d, state_type state, boost::system::error_code& ec)
406
392
fds.events = POLLIN;
407
393
fds.revents = 0 ;
408
394
int timeout = (state & user_set_non_blocking) ? 0 : -1 ;
409
- errno = 0 ;
410
- int result = error_wrapper (:: poll (&fds, 1 , timeout), ec );
395
+ int result = :: poll (&fds, 1 , timeout) ;
396
+ get_last_error (ec, result < 0 );
411
397
if (result == 0 )
412
- ec = (state & user_set_non_blocking)
413
- ? boost::asio::error::would_block : boost::system::error_code ();
414
- else if (result > 0 )
415
- ec = boost::system::error_code ();
398
+ if (state & user_set_non_blocking)
399
+ ec = boost::asio::error::would_block;
416
400
return result;
417
401
}
418
402
@@ -429,13 +413,11 @@ int poll_write(int d, state_type state, boost::system::error_code& ec)
429
413
fds.events = POLLOUT;
430
414
fds.revents = 0 ;
431
415
int timeout = (state & user_set_non_blocking) ? 0 : -1 ;
432
- errno = 0 ;
433
- int result = error_wrapper (:: poll (&fds, 1 , timeout), ec );
416
+ int result = :: poll (&fds, 1 , timeout) ;
417
+ get_last_error (ec, result < 0 );
434
418
if (result == 0 )
435
- ec = (state & user_set_non_blocking)
436
- ? boost::asio::error::would_block : boost::system::error_code ();
437
- else if (result > 0 )
438
- ec = boost::system::error_code ();
419
+ if (state & user_set_non_blocking)
420
+ ec = boost::asio::error::would_block;
439
421
return result;
440
422
}
441
423
@@ -452,13 +434,11 @@ int poll_error(int d, state_type state, boost::system::error_code& ec)
452
434
fds.events = POLLPRI | POLLERR | POLLHUP;
453
435
fds.revents = 0 ;
454
436
int timeout = (state & user_set_non_blocking) ? 0 : -1 ;
455
- errno = 0 ;
456
- int result = error_wrapper (:: poll (&fds, 1 , timeout), ec );
437
+ int result = :: poll (&fds, 1 , timeout) ;
438
+ get_last_error (ec, result < 0 );
457
439
if (result == 0 )
458
- ec = (state & user_set_non_blocking)
459
- ? boost::asio::error::would_block : boost::system::error_code ();
460
- else if (result > 0 )
461
- ec = boost::system::error_code ();
440
+ if (state & user_set_non_blocking)
441
+ ec = boost::asio::error::would_block;
462
442
return result;
463
443
}
464
444
0 commit comments