OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 SANDBOX_MAC_MACH_MESSAGE_SERVER_H_ | 5 #ifndef SANDBOX_MAC_MACH_MESSAGE_SERVER_H_ |
6 #define SANDBOX_MAC_MACH_MESSAGE_SERVER_H_ | 6 #define SANDBOX_MAC_MACH_MESSAGE_SERVER_H_ |
7 | 7 |
8 #include <dispatch/dispatch.h> | 8 #include <dispatch/dispatch.h> |
9 #include <mach/mach.h> | 9 #include <mach/mach.h> |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 protected: | 26 protected: |
27 virtual ~MessageDemuxer() {} | 27 virtual ~MessageDemuxer() {} |
28 }; | 28 }; |
29 | 29 |
30 // A Mach message server that operates a receive port. Messages are received | 30 // A Mach message server that operates a receive port. Messages are received |
31 // and then passed to the MessageDemuxer for handling. The Demuxer | 31 // and then passed to the MessageDemuxer for handling. The Demuxer |
32 // can use the server class to send a reply, forward the message to a | 32 // can use the server class to send a reply, forward the message to a |
33 // different port, or reply to the message with a MIG error. | 33 // different port, or reply to the message with a MIG error. |
34 class MachMessageServer { | 34 class MachMessageServer { |
35 public: | 35 public: |
36 MachMessageServer(MessageDemuxer* demuxer, mach_msg_size_t buffer_size); | 36 // Creates a new Mach message server that will send messages to |demuxer| |
| 37 // for handling. If the |server_receive_right| is non-NULL, this class will |
| 38 // take ownership of the port and it will be used to receive messages. |
| 39 // Otherwise the server will create a new receive right. |
| 40 // The maximum size of messages is specified by |buffer_size|. |
| 41 MachMessageServer(MessageDemuxer* demuxer, |
| 42 mach_port_t server_receive_right, |
| 43 mach_msg_size_t buffer_size); |
37 ~MachMessageServer(); | 44 ~MachMessageServer(); |
38 | 45 |
39 // Initializes the class and starts running the message server. If this | 46 // Initializes the class and starts running the message server. If this |
40 // returns false, no other methods may be called on this class. | 47 // returns false, no other methods may be called on this class. |
41 bool Initialize(); | 48 bool Initialize(); |
42 | 49 |
43 // Given a received request message, returns the PID of the sending process. | 50 // Given a received request message, returns the PID of the sending process. |
44 pid_t GetMessageSenderPID(mach_msg_header_t* request); | 51 pid_t GetMessageSenderPID(mach_msg_header_t* request); |
45 | 52 |
46 // Sends a reply message. Returns true if the message was sent successfully. | 53 // Sends a reply message. Returns true if the message was sent successfully. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 base::mac::ScopedMachVM request_buffer_; | 86 base::mac::ScopedMachVM request_buffer_; |
80 base::mac::ScopedMachVM reply_buffer_; | 87 base::mac::ScopedMachVM reply_buffer_; |
81 | 88 |
82 // Whether or not ForwardMessage() was called during ReceiveMessage(). | 89 // Whether or not ForwardMessage() was called during ReceiveMessage(). |
83 bool did_forward_message_; | 90 bool did_forward_message_; |
84 }; | 91 }; |
85 | 92 |
86 } // namespace sandbox | 93 } // namespace sandbox |
87 | 94 |
88 #endif // SANDBOX_MAC_MACH_MESSAGE_SERVER_H_ | 95 #endif // SANDBOX_MAC_MACH_MESSAGE_SERVER_H_ |
OLD | NEW |