Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(757)

Side by Side Diff: src/platform-macos.cc

Issue 42330: Add a close method to sockets (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/platform-linux.cc ('k') | src/platform-win32.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 // 592 //
593 593
594 class MacOSSocket : public Socket { 594 class MacOSSocket : public Socket {
595 public: 595 public:
596 explicit MacOSSocket() { 596 explicit MacOSSocket() {
597 // Create the socket. 597 // Create the socket.
598 socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 598 socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
599 } 599 }
600 explicit MacOSSocket(int socket): socket_(socket) { } 600 explicit MacOSSocket(int socket): socket_(socket) { }
601 601
602 602 virtual ~MacOSSocket() { Close(); }
603 virtual ~MacOSSocket() {
604 if (IsValid()) {
605 // Close socket.
606 close(socket_);
607 }
608 }
609 603
610 // Server initialization. 604 // Server initialization.
611 bool Bind(const int port); 605 bool Bind(const int port);
612 bool Listen(int backlog) const; 606 bool Listen(int backlog) const;
613 Socket* Accept() const; 607 Socket* Accept() const;
614 608
615 // Client initialization. 609 // Client initialization.
616 bool Connect(const char* host, const char* port); 610 bool Connect(const char* host, const char* port);
617 611
612 // Close.
613 bool Close();
614
618 // Data Transimission 615 // Data Transimission
619 int Send(const char* data, int len) const; 616 int Send(const char* data, int len) const;
620 int Receive(char* data, int len) const; 617 int Receive(char* data, int len) const;
621 618
622 bool IsValid() const { return socket_ != -1; } 619 bool IsValid() const { return socket_ != -1; }
623 620
624 private: 621 private:
625 int socket_; 622 int socket_;
626 }; 623 };
627 624
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 if (status != 0) { 686 if (status != 0) {
690 return false; 687 return false;
691 } 688 }
692 689
693 // Connect. 690 // Connect.
694 status = connect(socket_, result->ai_addr, result->ai_addrlen); 691 status = connect(socket_, result->ai_addr, result->ai_addrlen);
695 return status == 0; 692 return status == 0;
696 } 693 }
697 694
698 695
696 bool MacOSSocket::Close() {
697 if (IsValid()) {
698 // Close socket.
699 int status = close(socket_);
700 socket_ = -1;
701 return status == 0;
702 }
703 return true;
704 }
705
706
699 int MacOSSocket::Send(const char* data, int len) const { 707 int MacOSSocket::Send(const char* data, int len) const {
700 int status = send(socket_, data, len, 0); 708 int status = send(socket_, data, len, 0);
701 return status; 709 return status;
702 } 710 }
703 711
704 712
705 int MacOSSocket::Receive(char* data, int len) const { 713 int MacOSSocket::Receive(char* data, int len) const {
706 int status = recv(socket_, data, len, 0); 714 int status = recv(socket_, data, len, 0);
707 return status; 715 return status;
708 } 716 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 } 845 }
838 846
839 // This sampler is no longer the active sampler. 847 // This sampler is no longer the active sampler.
840 active_sampler_ = NULL; 848 active_sampler_ = NULL;
841 active_ = false; 849 active_ = false;
842 } 850 }
843 851
844 #endif // ENABLE_LOGGING_AND_PROFILING 852 #endif // ENABLE_LOGGING_AND_PROFILING
845 853
846 } } // namespace v8::internal 854 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-linux.cc ('k') | src/platform-win32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698