Comment: | OFWriteFailedException: Add -[bytesWritten]
This allows retrieving the number of bytes already written before the |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
2ae01218ef469cad01375dd3e120ec05 |
User & Date: | js on 2017-06-12 22:29:41 |
Other Links: | manifest | tags |
2017-06-13
| ||
23:08 | runtime: Add initial morphos-library.m check-in: 0d6873e122 user: js tags: trunk | |
2017-06-12
| ||
22:29 | OFWriteFailedException: Add -[bytesWritten] check-in: 2ae01218ef user: js tags: trunk | |
20:39 | Add support for AltiVec detection on MorphOS check-in: 1f9070d204 user: js tags: trunk | |
Modified src/OFFile.m from [b2ec5b887b] to [72431db710].
︙ | ︙ | |||
392 393 394 395 396 397 398 399 400 401 | - (void)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { if (_handle == OF_INVALID_FILE_HANDLE) @throw [OFNotOpenException exceptionWithObject: self]; #if defined(OF_WINDOWS) if (length > INT_MAX) @throw [OFOutOfRangeException exception]; | > > | > > > > | > > > | > > > > > > > | 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | - (void)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { if (_handle == OF_INVALID_FILE_HANDLE) @throw [OFNotOpenException exceptionWithObject: self]; #if defined(OF_WINDOWS) int bytesWritten; if (length > INT_MAX) @throw [OFOutOfRangeException exception]; if ((bytesWritten = write(_handle, buffer, (int)length)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: errno]; #elif defined(OF_MORPHOS) LONG bytesWritten; if (length > LONG_MAX) @throw [OFOutOfRangeException exception]; if (_handle->append) { if (Seek64(_handle->handle, 0, OFFSET_END) == -1) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: EIO]; } if ((bytesWritten = Write(_handle->handle, (void *)buffer, length)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: EIO]; #else ssize_t bytesWritten; if (length > SSIZE_MAX) @throw [OFOutOfRangeException exception]; if ((bytesWritten = write(_handle, buffer, length)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: errno]; #endif if ((size_t)bytesWritten != length) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: bytesWritten errNo: 0]; } - (of_offset_t)lowlevelSeekToOffset: (of_offset_t)offset whence: (int)whence { of_offset_t ret; |
︙ | ︙ |
Modified src/OFProcess.m from [a980832db2] to [b2487462e5].
︙ | ︙ | |||
484 485 486 487 488 489 490 491 492 493 494 495 496 | return ret; } - (void)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { #ifndef OF_WINDOWS if (_writePipe[1] == -1) @throw [OFNotOpenException exceptionWithObject: self]; if (length > SSIZE_MAX) @throw [OFOutOfRangeException exception]; | > > | > | | | > > > > > > > | 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 | return ret; } - (void)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { #ifndef OF_WINDOWS ssize_t bytesWritten; if (_writePipe[1] == -1) @throw [OFNotOpenException exceptionWithObject: self]; if (length > SSIZE_MAX) @throw [OFOutOfRangeException exception]; if ((bytesWritten = write(_writePipe[1], buffer, length)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: errno]; #else DWORD bytesWritten; if (length > UINT32_MAX) @throw [OFOutOfRangeException exception]; if (_writePipe[1] == NULL) @throw [OFNotOpenException exceptionWithObject: self]; if (!WriteFile(_writePipe[1], buffer, (DWORD)length, &bytesWritten, NULL)) { int errNo = EIO; if (GetLastError() == ERROR_BROKEN_PIPE) errNo = EPIPE; @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: errNo]; } #endif if ((size_t)bytesWritten != length) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: bytesWritten errNo: 0]; } - (int)fileDescriptorForReading { #ifndef OF_WINDOWS return _readPipe[0]; #else |
︙ | ︙ |
Modified src/OFStdIOStream.m from [ed0f11c59f] to [cf1f27b3cb].
︙ | ︙ | |||
222 223 224 225 226 227 228 229 230 231 | length: (size_t)length { #ifndef OF_MORPHOS if (_fd == -1) @throw [OFNotOpenException exceptionWithObject: self]; # ifndef OF_WINDOWS if (length > SSIZE_MAX) @throw [OFOutOfRangeException exception]; | > > | > > > | > > > | > > > > > > > | 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | length: (size_t)length { #ifndef OF_MORPHOS if (_fd == -1) @throw [OFNotOpenException exceptionWithObject: self]; # ifndef OF_WINDOWS ssize_t bytesWritten; if (length > SSIZE_MAX) @throw [OFOutOfRangeException exception]; if ((bytesWritten = write(_fd, buffer, length)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: errno]; # else int bytesWritten; if (length > INT_MAX) @throw [OFOutOfRangeException exception]; if ((bytesWritten = write(_fd, buffer, (int)length)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: errno]; # endif #else LONG bytesWritten; if (_handle == 0) @throw [OFNotOpenException exceptionWithObject: self]; if (length > SSIZE_MAX) @throw [OFOutOfRangeException exception]; if ((bytesWritten = Write(_handle, (void *)buffer, length)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: EIO]; #endif if ((size_t)bytesWritten != length) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: bytesWritten errNo: 0]; } #if !defined(OF_WINDOWS) && !defined(OF_MORPHOS) - (int)fileDescriptorForReading { return _fd; } |
︙ | ︙ |
Modified src/OFStdIOStream_Win32Console.m from [e75a0d88c9] to [451d779be8].
︙ | ︙ | |||
229 230 231 232 233 234 235 | @throw [OFOutOfRangeException exception]; if (_incompleteUTF8SurrogateLen > 0) { of_unichar_t c; char16_t UTF16[2]; ssize_t UTF8Len; size_t toCopy; | | | 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | @throw [OFOutOfRangeException exception]; if (_incompleteUTF8SurrogateLen > 0) { of_unichar_t c; char16_t UTF16[2]; ssize_t UTF8Len; size_t toCopy; DWORD UTF16Len, bytesWritten; UTF8Len = -of_string_utf8_decode( _incompleteUTF8Surrogate, _incompleteUTF8SurrogateLen, &c); OF_ENSURE(UTF8Len > 0); toCopy = UTF8Len - _incompleteUTF8SurrogateLen; |
︙ | ︙ | |||
267 268 269 270 271 272 273 | UTF16Len = 2; } else { UTF16[0] = c; UTF16Len = 1; } } | | > > > > > > > | > | | | 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | UTF16Len = 2; } else { UTF16[0] = c; UTF16Len = 1; } } if (!WriteConsoleW(_handle, UTF16, UTF16Len, &bytesWritten, NULL)) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: UTF16Len * 2 bytesWritten: 0 errNo: EIO]; if (bytesWritten != UTF16Len) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: UTF16Len * 2 bytesWritten: bytesWritten * 2 errNo: 0]; _incompleteUTF8SurrogateLen = 0; i += toCopy; } tmp = [self allocMemoryWithSize: sizeof(char16_t) count: length * 2]; @try { DWORD bytesWritten; while (i < length) { of_unichar_t c; ssize_t UTF8Len; UTF8Len = of_string_utf8_decode(buffer + i, length - i, &c); |
︙ | ︙ | |||
319 320 321 322 323 324 325 | i += UTF8Len; } if (j > UINT32_MAX) @throw [OFOutOfRangeException exception]; | | > > > > > > | > | | 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | i += UTF8Len; } if (j > UINT32_MAX) @throw [OFOutOfRangeException exception]; if (!WriteConsoleW(_handle, tmp, (DWORD)j, &bytesWritten, NULL)) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: j * 2 bytesWritten: 0 errNo: EIO]; if (bytesWritten != j) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: j * 2 bytesWritten: bytesWritten * 2 errNo: 0]; } @finally { [self freeMemory: tmp]; } } @end |
Modified src/OFStreamSocket.m from [eec652ecb7] to [272212f745].
︙ | ︙ | |||
90 91 92 93 94 95 96 97 98 99 | - (void)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { if (_socket == INVALID_SOCKET) @throw [OFNotOpenException exceptionWithObject: self]; #ifndef OF_WINDOWS if (length > SSIZE_MAX) @throw [OFOutOfRangeException exception]; | > > | > > > | > > > > > > > | 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 | - (void)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { if (_socket == INVALID_SOCKET) @throw [OFNotOpenException exceptionWithObject: self]; #ifndef OF_WINDOWS ssize_t bytesWritten; if (length > SSIZE_MAX) @throw [OFOutOfRangeException exception]; if ((bytesWritten = send(_socket, buffer, length, 0)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: of_socket_errno()]; #else int bytesWritten; if (length > INT_MAX) @throw [OFOutOfRangeException exception]; if ((bytesWritten = send(_socket, buffer, (int)length, 0)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: of_socket_errno()]; #endif if ((size_t)bytesWritten != length) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: bytesWritten errNo: 0]; } #ifdef OF_WINDOWS - (void)setBlocking: (bool)enable { u_long v = enable; _blocking = enable; |
︙ | ︙ |
Modified src/OFTCPSocket+SOCKS5.m from [f778008a7d] to [c322fa746c].
︙ | ︙ | |||
31 32 33 34 35 36 37 | /* Reference for static linking */ int _OFTCPSocket_SOCKS5_reference; static void send_or_exception(OFTCPSocket *self, of_socket_t socket, char *buffer, int length) { | > > > > > > | > > > > > > > | 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 | /* Reference for static linking */ int _OFTCPSocket_SOCKS5_reference; static void send_or_exception(OFTCPSocket *self, of_socket_t socket, char *buffer, int length) { #ifndef OF_WINDOWS ssize_t bytesWritten; #else int bytesWritten; #endif if ((bytesWritten = send(socket, (const void *)buffer, length, 0)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: of_socket_errno()]; if ((int)bytesWritten != length) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: bytesWritten errNo: 0]; } static void recv_exact(OFTCPSocket *self, of_socket_t socket, char *buffer, int length) { while (length > 0) { ssize_t ret = recv(socket, (void *)buffer, length, 0); |
︙ | ︙ |
Modified src/OFUDPSocket.m from [a9d215ce51] to [c8e3c83553].
︙ | ︙ | |||
584 585 586 587 588 589 590 591 592 593 | length: (size_t)length receiver: (const of_udp_socket_address_t *)receiver { if (_socket == INVALID_SOCKET) @throw [OFNotOpenException exceptionWithObject: self]; #ifndef OF_WINDOWS if (length > SSIZE_MAX) @throw [OFOutOfRangeException exception]; | > > | | < > > > | | > > > > > > > | 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 | length: (size_t)length receiver: (const of_udp_socket_address_t *)receiver { if (_socket == INVALID_SOCKET) @throw [OFNotOpenException exceptionWithObject: self]; #ifndef OF_WINDOWS ssize_t bytesWritten; if (length > SSIZE_MAX) @throw [OFOutOfRangeException exception]; if ((bytesWritten = sendto(_socket, buffer, length, 0, (struct sockaddr *)&receiver->address, receiver->length)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: of_socket_errno()]; #else int bytesWritten; if (length > INT_MAX) @throw [OFOutOfRangeException exception]; if ((bytesWritten = sendto(_socket, buffer, (int)length, 0, (struct sockaddr *)&receiver->address, receiver->length)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: of_socket_errno()]; #endif if ((size_t)bytesWritten != length) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: bytesWritten errNo: 0]; } - (void)cancelAsyncRequests { [OFRunLoop of_cancelAsyncRequestsForObject: self]; } |
︙ | ︙ |
Modified src/exceptions/OFWriteFailedException.h from [65c0a33d30] to [63e6e7e007].
︙ | ︙ | |||
21 22 23 24 25 26 27 28 29 30 | /*! * @class OFWriteFailedException \ * OFWriteFailedException.h ObjFW/OFWriteFailedException.h * * @brief An exception indicating that writing to an object failed. */ @interface OFWriteFailedException: OFReadOrWriteFailedException @end OF_ASSUME_NONNULL_END | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 | /*! * @class OFWriteFailedException \ * OFWriteFailedException.h ObjFW/OFWriteFailedException.h * * @brief An exception indicating that writing to an object failed. */ @interface OFWriteFailedException: OFReadOrWriteFailedException { size_t _bytesWritten; } /*! * The number of bytes already written before the write failed. * * This can be used to make sure that a retry does not write data already * written before. */ @property (readonly, nonatomic) size_t bytesWritten; + (instancetype)exceptionWithObject: (id)object requestedLength: (size_t)requestedLength errNo: (int)errNo OF_UNAVAILABLE; /*! * @brief Creates a new, autoreleased write failed exception. * * @param object The object from which reading or to which writing failed * @param requestedLength The requested length of the data that could not be * read / written * @param bytesWritten The amount of bytes already written before the write * failed * @param errNo The errno of the error that occurred * @return A new, autoreleased write failed exception */ + (instancetype)exceptionWithObject: (id)object requestedLength: (size_t)requestedLength bytesWritten: (size_t)bytesWritten errNo: (int)errNo; - initWithObject: (id)object requestedLength: (size_t)requestedLength errNo: (int)errNo OF_UNAVAILABLE; /*! * @brief Initializes an already allocated write failed exception. * * @param object The object from which reading or to which writing failed * @param requestedLength The requested length of the data that could not be * read / written * @param bytesWritten The amount of bytes already written before the write * failed * @param errNo The errno of the error that occurred * @return A new open file failed exception */ - initWithObject: (id)object requestedLength: (size_t)requestedLength bytesWritten: (size_t)bytesWritten errNo: (int)errNo OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END |
Modified src/exceptions/OFWriteFailedException.m from [e7b34fe947] to [16fd1ae620].
︙ | ︙ | |||
16 17 18 19 20 21 22 23 24 25 | #include "config.h" #import "OFWriteFailedException.h" #import "OFString.h" @implementation OFWriteFailedException - (OFString *)description { return [OFString stringWithFormat: | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > | | 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 | #include "config.h" #import "OFWriteFailedException.h" #import "OFString.h" @implementation OFWriteFailedException @synthesize bytesWritten = _bytesWritten; + (instancetype)exceptionWithObject: (id)object requestedLength: (size_t)requestedLength errNo: (int)errNo { return [[[self alloc] initWithObject: object requestedLength: requestedLength errNo: errNo] autorelease]; } + (instancetype)exceptionWithObject: (id)object requestedLength: (size_t)requestedLength bytesWritten: (size_t)bytesWritten errNo: (int)errNo { return [[[self alloc] initWithObject: object requestedLength: requestedLength bytesWritten: bytesWritten errNo: errNo] autorelease]; } - initWithObject: (id)object requestedLength: (size_t)requestedLength errNo: (int)errNo { OF_INVALID_INIT_METHOD } - initWithObject: (id)object requestedLength: (size_t)requestedLength bytesWritten: (size_t)bytesWritten errNo: (int)errNo { self = [super initWithObject: object requestedLength: requestedLength errNo: errNo]; _bytesWritten = bytesWritten; return self; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to write %zu bytes (after %zu bytes written) to an " @"object of type %@: %@", _requestedLength, _bytesWritten, [_object class], of_strerror(_errNo)]; } @end |