unix_socket.h 1.44 KB
Newer Older
gejun's avatar
gejun committed
1
// Copyright (c) 2014 Baidu, Inc.
gejun's avatar
gejun committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Author: Jiang,Rujie(jiangrujie@baidu.com)
gejun's avatar
gejun committed
16 17
// Date: Mon. Jan 27  23:08:35 CST 2014

gejun's avatar
gejun committed
18 19
// Wrappers of unix domain sockets, mainly for unit-test of network stuff.

gejun's avatar
gejun committed
20 21
#ifndef BUTIL_UNIX_SOCKET_H
#define BUTIL_UNIX_SOCKET_H
gejun's avatar
gejun committed
22

23
namespace butil {
gejun's avatar
gejun committed
24 25 26 27 28 29 30 31 32 33 34 35 36

// Create an unix domain socket at `sockname' and listen to it.
// If remove_previous_file is true or absent, remove previous file before
// creating the socket.
// Returns the file descriptor on success, -1 otherwise and errno is set.
int unix_socket_listen(const char* sockname, bool remove_previous_file);
int unix_socket_listen(const char* sockname);

// Create an unix domain socket and connect it to another listening unix domain
// socket at `sockname'.
// Returns the file descriptor on success, -1 otherwise and errno is set.
int unix_socket_connect(const char* sockname);

37
}  // namespace butil
gejun's avatar
gejun committed
38

gejun's avatar
gejun committed
39
#endif  // BUTIL_UNIX_SOCKET_H