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

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

Issue 42387: Change the socket close to shutdown (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.h ('k') | src/platform-linux.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 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 // FreeBSD socket support. 643 // FreeBSD socket support.
644 // 644 //
645 645
646 class FreeBSDSocket : public Socket { 646 class FreeBSDSocket : public Socket {
647 public: 647 public:
648 explicit FreeBSDSocket() { 648 explicit FreeBSDSocket() {
649 // Create the socket. 649 // Create the socket.
650 socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 650 socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
651 } 651 }
652 explicit FreeBSDSocket(int socket): socket_(socket) { } 652 explicit FreeBSDSocket(int socket): socket_(socket) { }
653 653 virtual ~FreeBSDSocket() { Shutdown(); }
654 virtual ~FreeBSDSocket() { Close(); }
655 654
656 // Server initialization. 655 // Server initialization.
657 bool Bind(const int port); 656 bool Bind(const int port);
658 bool Listen(int backlog) const; 657 bool Listen(int backlog) const;
659 Socket* Accept() const; 658 Socket* Accept() const;
660 659
661 // Client initialization. 660 // Client initialization.
662 bool Connect(const char* host, const char* port); 661 bool Connect(const char* host, const char* port);
663 662
664 // Close. 663 // Shutdown socket for both read and write.
665 bool Close(); 664 bool Shutdown();
666 665
667 // Data Transimission 666 // Data Transimission
668 int Send(const char* data, int len) const; 667 int Send(const char* data, int len) const;
669 int Receive(char* data, int len) const; 668 int Receive(char* data, int len) const;
670 669
671 bool IsValid() const { return socket_ != -1; } 670 bool IsValid() const { return socket_ != -1; }
672 671
673 private: 672 private:
674 int socket_; 673 int socket_;
675 }; 674 };
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 return false; 732 return false;
734 } 733 }
735 734
736 // Connect. 735 // Connect.
737 status = connect(socket_, result->ai_addr, result->ai_addrlen); 736 status = connect(socket_, result->ai_addr, result->ai_addrlen);
738 freeaddrinfo(result); 737 freeaddrinfo(result);
739 return status == 0; 738 return status == 0;
740 } 739 }
741 740
742 741
743 bool FreeBSDSocket::Close() { 742 bool FreeBSDSocket::Shutdown() {
744 if (IsValid()) { 743 if (IsValid()) {
745 // Close socket. 744 // Shutdown socket for both read and write.
746 int status = close(socket_); 745 int status = shutdown(socket_, SHUT_RDWR);
746 close(socket_);
747 socket_ = -1; 747 socket_ = -1;
748 return status == 0; 748 return status == 0;
749 } 749 }
750 return true; 750 return true;
751 } 751 }
752 752
753
753 int FreeBSDSocket::Send(const char* data, int len) const { 754 int FreeBSDSocket::Send(const char* data, int len) const {
754 int status = send(socket_, data, len, 0); 755 int status = send(socket_, data, len, 0);
755 return status; 756 return status;
756 } 757 }
757 758
758 759
759 int FreeBSDSocket::Receive(char* data, int len) const { 760 int FreeBSDSocket::Receive(char* data, int len) const {
760 int status = recv(socket_, data, len, 0); 761 int status = recv(socket_, data, len, 0);
761 return status; 762 return status;
762 } 763 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 } 892 }
892 893
893 // This sampler is no longer the active sampler. 894 // This sampler is no longer the active sampler.
894 active_sampler_ = NULL; 895 active_sampler_ = NULL;
895 active_ = false; 896 active_ = false;
896 } 897 }
897 898
898 #endif // ENABLE_LOGGING_AND_PROFILING 899 #endif // ENABLE_LOGGING_AND_PROFILING
899 900
900 } } // namespace v8::internal 901 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform.h ('k') | src/platform-linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698