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

Side by Side Diff: chrome/browser/extensions/api/socket/socket.h

Issue 10134008: Add bind(), recvFrom(), sendTo() for UDP socket. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Update Created 8 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "chrome/browser/extensions/api/api_resource.h" 12 #include "chrome/browser/extensions/api/api_resource.h"
13 #include "net/base/io_buffer.h" 13 #include "net/base/io_buffer.h"
14 14
15 namespace net { 15 namespace net {
16 class AddressList;
17 class IPEndPoint;
16 class Socket; 18 class Socket;
17 } 19 }
18 20
19 namespace extensions { 21 namespace extensions {
20 22
21 // A Socket wraps a low-level socket and includes housekeeping information that 23 // A Socket wraps a low-level socket and includes housekeeping information that
22 // we need to manage it in the context of an extension. 24 // we need to manage it in the context of an extension.
23 class Socket : public APIResource { 25 class Socket : public APIResource {
24 public: 26 public:
25 virtual ~Socket(); 27 virtual ~Socket();
26 28
27 // Returns true iff the socket was able to properly initialize itself. 29 // Returns net::OK if successful, or an error code otherwise.
28 virtual bool IsValid() = 0; 30 virtual int Connect(const std::string& address, int port) = 0;
31 virtual void Disconnect() = 0;
29 32
30 // Returns net::OK if successful, or an error code otherwise. 33 virtual int Bind(const std::string& address, int port) = 0;
31 virtual int Connect() = 0;
32 virtual void Disconnect() = 0;
33 34
34 // Returns the number of bytes read into the buffer, or a negative number if 35 // Returns the number of bytes read into the buffer, or a negative number if
35 // an error occurred. 36 // an error occurred.
36 virtual int Read(scoped_refptr<net::IOBuffer> io_buffer, int io_buffer_size); 37 virtual int Read(scoped_refptr<net::IOBuffer> io_buffer,
38 int io_buffer_size) = 0;
37 39
38 // Returns the number of bytes successfully written, or a negative error 40 // Returns the number of bytes successfully written, or a negative error
39 // code. Note that ERR_IO_PENDING means that the operation blocked, in which 41 // code. Note that ERR_IO_PENDING means that the operation blocked, in which
40 // case |event_notifier| (supplied at socket creation) will eventually be 42 // case |event_notifier| (supplied at socket creation) will eventually be
41 // called with the final result (again, either a nonnegative number of bytes 43 // called with the final result (again, either a nonnegative number of bytes
42 // written, or a negative error). 44 // written, or a negative error).
43 virtual int Write(scoped_refptr<net::IOBuffer> io_buffer, int bytes); 45 virtual int Write(scoped_refptr<net::IOBuffer> io_buffer,
46 int byte_count) = 0;
44 47
45 virtual void OnDataRead(scoped_refptr<net::IOBuffer> io_buffer, int result); 48 virtual int RecvFrom(scoped_refptr<net::IOBuffer> io_buffer,
49 int io_buffer_size,
50 net::IPEndPoint *address) = 0;
51 virtual int SendTo(scoped_refptr<net::IOBuffer> io_buffer,
52 int byte_count,
53 const std::string& address,
54 int port) = 0;
55
56 virtual void OnDataRead(scoped_refptr<net::IOBuffer> io_buffer,
57 net::IPEndPoint *address,
58 int result);
46 virtual void OnWriteComplete(int result); 59 virtual void OnWriteComplete(int result);
47 60
61 static bool StringAndPortToAddressList(const std::string& ip_address_str,
62 int port,
63 net::AddressList* address_list);
64 static bool StringAndPortToIPEndPoint(const std::string& ip_address_str,
65 int port,
66 net::IPEndPoint* ip_end_point);
67 static void IPEndPointToStringAndPort(const net::IPEndPoint& address,
68 std::string* ip_address_str,
69 int* port);
70
48 protected: 71 protected:
49 Socket(const std::string& address, int port, 72 explicit Socket(APIResourceEventNotifier* event_notifier);
50 APIResourceEventNotifier* event_notifier);
51 virtual net::Socket* socket() = 0;
52 73
53 const std::string address_; 74 const std::string address_;
54 int port_; 75 int port_;
55 bool is_connected_; 76 bool is_connected_;
56 }; 77 };
57 78
58 } // namespace extensions 79 } // namespace extensions
59 80
60 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ 81 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/api_resource_event_notifier.cc ('k') | chrome/browser/extensions/api/socket/socket.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698