blob: bface16532e945958ceda9356a827f69c8b800df [file] [log] [blame]
Darin Petkov633ac6f2011-07-08 13:56:13 -07001// 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 Petkove0a312e2011-07-20 13:45:28 -070010#include <base/basictypes.h>
11
Darin Petkov633ac6f2011-07-08 13:56:13 -070012namespace shill {
13
14// A "sys/socket.h" abstraction allowing mocking in tests.
15class 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 Petkove0a312e2011-07-20 13:45:28 -070025 // ioctl
26 virtual int Ioctl(int d, int request, void *argp);
27
Darin Petkov633ac6f2011-07-08 13:56:13 -070028 // 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 Petkove0a312e2011-07-20 13:45:28 -070039class 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 Petkov633ac6f2011-07-08 13:56:13 -070051} // namespace shill
52
53#endif // SHILL_SOCKETS_H_