Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef SHILL_SOCKETS_H_ |
| 6 | #define SHILL_SOCKETS_H_ |
| 7 | |
| 8 | #include <sys/types.h> |
| 9 | |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 10 | #include <base/basictypes.h> |
| 11 | |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 12 | namespace shill { |
| 13 | |
| 14 | // A "sys/socket.h" abstraction allowing mocking in tests. |
| 15 | class Sockets { |
| 16 | public: |
| 17 | virtual ~Sockets(); |
| 18 | |
| 19 | // bind |
| 20 | virtual int Bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen); |
| 21 | |
| 22 | // close |
| 23 | virtual int Close(int fd); |
| 24 | |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 25 | // ioctl |
| 26 | virtual int Ioctl(int d, int request, void *argp); |
| 27 | |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 28 | // send |
| 29 | virtual ssize_t Send(int sockfd, const void *buf, size_t len, int flags); |
| 30 | |
| 31 | // sendto |
| 32 | virtual ssize_t SendTo(int sockfd, const void *buf, size_t len, int flags, |
| 33 | const struct sockaddr *dest_addr, socklen_t addrlen); |
| 34 | |
| 35 | // socket |
| 36 | virtual int Socket(int domain, int type, int protocol); |
| 37 | }; |
| 38 | |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 39 | class ScopedSocketCloser { |
| 40 | public: |
| 41 | ScopedSocketCloser(Sockets *sockets, int fd); |
| 42 | ~ScopedSocketCloser(); |
| 43 | |
| 44 | private: |
| 45 | Sockets *sockets_; |
| 46 | int fd_; |
| 47 | |
| 48 | DISALLOW_COPY_AND_ASSIGN(ScopedSocketCloser); |
| 49 | }; |
| 50 | |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 51 | } // namespace shill |
| 52 | |
| 53 | #endif // SHILL_SOCKETS_H_ |