Overview
Comment: | errno is not thread-safe on Win32, therefore use something else. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
cda65a18998a39b45cbfdbb0b69f03d5 |
User & Date: | js on 2008-12-23 17:10:44 |
Other Links: | manifest | tags |
Context
2008-12-24
| ||
11:55 | Add methods to initalize from and append from formatted C strings. check-in: 486760ed2b user: js tags: trunk | |
2008-12-23
| ||
17:10 | errno is not thread-safe on Win32, therefore use something else. check-in: cda65a1899 user: js tags: trunk | |
16:51 | Add Win32 support to OFTCPSocket. Even IPv6 works! check-in: 839112196f user: js tags: trunk | |
Changes
Modified src/OFExceptions.m from [b883a225ce] to [ddf754ab44].
︙ | ︙ | |||
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #import "config.h" #define _GNU_SOURCE #import <stdio.h> #import <stdlib.h> #import <string.h> #import <errno.h> #import "OFExceptions.h" #ifndef HAVE_ASPRINTF #import "asprintf.h" #endif | > > > > > > > > > > > > > | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #import "config.h" #define _GNU_SOURCE #import <stdio.h> #import <stdlib.h> #import <string.h> #ifndef _WIN32 #import <errno.h> #define GET_ERR errno #define GET_SOCK_ERR errno #define ERRFMT "Error string was: %s" #define ERRPARAM strerror(err) #else #import <windows.h> #define GET_ERR GetLastError() #define GET_SOCK_ERR WSAGetLastError() #define ERRFMT "Error code was: %d" #define ERRPARAM err #endif #import "OFExceptions.h" #ifndef HAVE_ASPRINTF #import "asprintf.h" #endif |
︙ | ︙ | |||
200 201 202 203 204 205 206 | - initWithObject: (id)obj andPath: (const char*)path_ andMode: (const char*)mode_ { if ((self = [super initWithObject: obj])) { path = (path_ != NULL ? strdup(path_) : NULL); mode = (mode_ != NULL ? strdup(mode_) : NULL); | | | 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | - initWithObject: (id)obj andPath: (const char*)path_ andMode: (const char*)mode_ { if ((self = [super initWithObject: obj])) { path = (path_ != NULL ? strdup(path_) : NULL); mode = (mode_ != NULL ? strdup(mode_) : NULL); err = GET_ERR; } return self; } - free { |
︙ | ︙ | |||
222 223 224 225 226 227 228 | - (const char*)cString { if (string != NULL) return string; asprintf(&string, "Failed to open file %s with mode %s in object of " | | < | 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | - (const char*)cString { if (string != NULL) return string; asprintf(&string, "Failed to open file %s with mode %s in object of " "class %s! " ERRFMT, path, mode, [self name], ERRPARAM); return string; } - (int)errNo { return err; |
︙ | ︙ | |||
269 270 271 272 273 274 275 | andSize: (size_t)size andNItems: (size_t)nitems { if ((self = [super initWithObject: obj])) { req_size = size; req_items = nitems; has_items = YES; | | | | 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | andSize: (size_t)size andNItems: (size_t)nitems { if ((self = [super initWithObject: obj])) { req_size = size; req_items = nitems; has_items = YES; err = GET_ERR; } return self; } - initWithObject: (id)obj andSize: (size_t)size { if ((self = [super initWithObject: obj])) { req_size = size; req_items = 0; has_items = NO; err = GET_ERR; } return self; } - (int)errNo { |
︙ | ︙ | |||
317 318 319 320 321 322 323 | - (const char*)cString { if (string != NULL) return string;; if (has_items) asprintf(&string, "Failed to read %zu items of size %zu in " | | | | < | | | < | 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | - (const char*)cString { if (string != NULL) return string;; if (has_items) asprintf(&string, "Failed to read %zu items of size %zu in " "object of class %s! " ERRFMT, req_items, req_size, [object name], ERRPARAM); else asprintf(&string, "Failed to read %zu bytes in object of class " "%s! " ERRFMT, req_size, [object name], ERRPARAM); return string; } @end @implementation OFWriteFailedException - (const char*)cString { if (string != NULL) return string; if (has_items) asprintf(&string, "Failed to write %zu items of size %zu in " "object of class %s! " ERRFMT, req_items, req_size, [object name], ERRPARAM); else asprintf(&string, "Failed to write %zu bytes in object of " "class %s! " ERRFMT, req_size, [object name], ERRFMT); return string; } @end @implementation OFSetOptionFailedException - (const char*)cString |
︙ | ︙ | |||
417 418 419 420 421 422 423 | - initWithObject: (id)obj andNode: (const char*)node_ andService: (const char*)service_ { if ((self = [super initWithObject: obj])) { node = (node_ != NULL ? strdup(node_) : NULL); service = (service_ != NULL ? strdup(service_) : NULL); | | | 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 | - initWithObject: (id)obj andNode: (const char*)node_ andService: (const char*)service_ { if ((self = [super initWithObject: obj])) { node = (node_ != NULL ? strdup(node_) : NULL); service = (service_ != NULL ? strdup(service_) : NULL); err = GET_SOCK_ERR; } return self; } - free { |
︙ | ︙ | |||
443 444 445 446 447 448 449 | return string; asprintf(&string, "The service %s on %s could not be translated to an " "address for an object of type %s. This means that either the node " "was not found, there is no such service on the node, there was a " "problem with the name server, there was a problem with your " "network connection or you specified an invalid node or service. " | | < | 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 | return string; asprintf(&string, "The service %s on %s could not be translated to an " "address for an object of type %s. This means that either the node " "was not found, there is no such service on the node, there was a " "problem with the name server, there was a problem with your " "network connection or you specified an invalid node or service. " ERRFMT, service, node, [object name], ERRPARAM); return string; } - (int)errNo { return err; |
︙ | ︙ | |||
482 483 484 485 486 487 488 | - initWithObject: (id)obj andHost: (const char*)host_ andPort: (uint16_t)port_ { if ((self = [super initWithObject: obj])) { host = (host_ != NULL ? strdup(host_) : NULL); port = port_; | | | < | 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 | - initWithObject: (id)obj andHost: (const char*)host_ andPort: (uint16_t)port_ { if ((self = [super initWithObject: obj])) { host = (host_ != NULL ? strdup(host_) : NULL); port = port_; err = GET_SOCK_ERR; } return self; } - free { if (host != NULL) free(host); return [super free]; } - (const char*)cString { if (string != NULL) return string; asprintf(&string, "A connection to %s:%d could not be established in " "object of type %s! " ERRFMT, host, port, [object name], ERRPARAM); return string; } - (int)errNo { return err; |
︙ | ︙ | |||
545 546 547 548 549 550 551 | andPort: (uint16_t)port_ andFamily: (int)family_ { if ((self = [super initWithObject: obj])) { host = (host_ != NULL ? strdup(host_) : NULL); port = port_; family = family_; | | | | | 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 | andPort: (uint16_t)port_ andFamily: (int)family_ { if ((self = [super initWithObject: obj])) { host = (host_ != NULL ? strdup(host_) : NULL); port = port_; family = family_; err = GET_SOCK_ERR; } return self; } - free { if (host != NULL) free(host); return [super free]; } - (const char*)cString { if (string != NULL) return string; asprintf(&string, "Binding to port %d on %s using family %d failed in " "object of type %s! " ERRFMT, port, host, family, [object name], ERRPARAM); return string; } - (int)errNo { return err; |
︙ | ︙ | |||
605 606 607 608 609 610 611 | } - initWithObject: (id)obj andBackLog: (int)backlog_ { if ((self = [super initWithObject: obj])) { backlog = backlog_; | | | < | | | 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 | } - initWithObject: (id)obj andBackLog: (int)backlog_ { if ((self = [super initWithObject: obj])) { backlog = backlog_; err = GET_SOCK_ERR; } return self; } - (const char*)cString { if (string != NULL) return string; asprintf(&string, "Failed to listen in socket of type %s with a back " "log of %d! "ERRFMT, [object name], backlog, ERRPARAM); return string; } - (int)errNo { return err; } - (int)backLog { return backlog; } @end @implementation OFAcceptFailedException - initWithObject: (id)obj { if ((self = [super initWithObject: obj])) err = GET_SOCK_ERR; return self; } - (const char*)cString { if (string != NULL) return string; asprintf(&string, "Failed to accept connection in socket of type %s! " ERRFMT, [object name], ERRPARAM); return string; } - (int)errNo { return err; } @end |