1/*- 2 * Copyright (c) 2009-2010 The FreeBSD Foundation 3 * All rights reserved. 4 * 5 * This software was developed by Pawel Jakub Dawidek under sponsorship from 6 * the FreeBSD Foundation. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 14 unchanged lines hidden (view full) --- 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30#include <sys/cdefs.h> |
31__FBSDID("$FreeBSD: head/sbin/hastd/proto.c 207371 2010-04-29 15:36:32Z pjd $"); |
32 |
33#include <sys/types.h> |
34#include <sys/queue.h> |
35#include <sys/socket.h> |
36 37#include <assert.h> 38#include <errno.h> 39#include <stdint.h> 40 41#include "proto.h" 42#include "proto_impl.h" 43 --- 200 unchanged lines hidden (view full) --- 244 245 assert(conn != NULL); 246 assert(conn->pc_magic == PROTO_CONN_MAGIC); 247 assert(conn->pc_proto != NULL); 248 249 conn->pc_proto->hp_remote_address(conn->pc_ctx, addr, size); 250} 251 |
252int 253proto_timeout(const struct proto_conn *conn, int timeout) 254{ 255 struct timeval tv; 256 int fd; 257 258 assert(conn != NULL); 259 assert(conn->pc_magic == PROTO_CONN_MAGIC); 260 assert(conn->pc_proto != NULL); 261 262 fd = proto_descriptor(conn); 263 if (fd < 0) 264 return (-1); 265 266 tv.tv_sec = timeout; 267 tv.tv_usec = 0; 268 if (setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)) < 0) 269 return (-1); 270 if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) 271 return (-1); 272 273 return (0); 274} 275 |
276void 277proto_close(struct proto_conn *conn) 278{ 279 280 assert(conn != NULL); 281 assert(conn->pc_magic == PROTO_CONN_MAGIC); 282 assert(conn->pc_proto != NULL); 283 284 conn->pc_proto->hp_close(conn->pc_ctx); 285 conn->pc_magic = 0; 286 free(conn); 287} |