1 /*
2 * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
3 * University Research and Technology
4 * Corporation. All rights reserved.
5 * Copyright (c) 2004-2006 The University of Tennessee and The University
6 * of Tennessee Research Foundation. All rights
7 * reserved.
8 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
9 * University of Stuttgart. All rights reserved.
10 * Copyright (c) 2004-2005 The Regents of the University of California.
11 * All rights reserved.
12 * Copyright (c) 2006-2013 Los Alamos National Security, LLC.
13 * All rights reserved.
14 * Copyright (c) 2010-2011 Cisco Systems, Inc. All rights reserved.
15 * Copyright (c) 2014-2017 Intel, Inc. All rights reserved.
16 * $COPYRIGHT$
17 *
18 * Additional copyrights may follow
19 *
20 * $HEADER$
21 */
22
23 #ifndef _MCA_OOB_TCP_CONNECTION_H_
24 #define _MCA_OOB_TCP_CONNECTION_H_
25
26 #include "orte_config.h"
27
28 #ifdef HAVE_SYS_TYPES_H
29 #include <sys/types.h>
30 #endif
31 #ifdef HAVE_SYS_SOCKET_H
32 #include <sys/socket.h>
33 #endif
34
35 #include "orte/util/threads.h"
36 #include "oob_tcp.h"
37 #include "oob_tcp_peer.h"
38
39 /* State machine for connection operations */
40 typedef struct {
41 opal_object_t super;
42 mca_oob_tcp_peer_t *peer;
43 opal_event_t ev;
44 } mca_oob_tcp_conn_op_t;
45 OBJ_CLASS_DECLARATION(mca_oob_tcp_conn_op_t);
46
47 #define CLOSE_THE_SOCKET(socket) \
48 do { \
49 shutdown(socket, 2); \
50 close(socket); \
51 } while(0)
52
53 #define ORTE_ACTIVATE_TCP_CONN_STATE(p, cbfunc) \
54 do { \
55 mca_oob_tcp_conn_op_t *cop; \
56 opal_output_verbose(5, orte_oob_base_framework.framework_output, \
57 "%s:[%s:%d] connect to %s", \
58 ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), \
59 __FILE__, __LINE__, \
60 ORTE_NAME_PRINT((&(p)->name))); \
61 cop = OBJ_NEW(mca_oob_tcp_conn_op_t); \
62 cop->peer = (p); \
63 ORTE_THREADSHIFT(cop, (p)->ev_base, (cbfunc), ORTE_MSG_PRI); \
64 } while(0);
65
66 #define ORTE_ACTIVATE_TCP_ACCEPT_STATE(s, a, cbfunc) \
67 do { \
68 mca_oob_tcp_conn_op_t *cop; \
69 cop = OBJ_NEW(mca_oob_tcp_conn_op_t); \
70 opal_event_set(orte_oob_base.ev_base, &cop->ev, s, \
71 OPAL_EV_READ, (cbfunc), cop); \
72 opal_event_set_priority(&cop->ev, ORTE_MSG_PRI); \
73 ORTE_POST_OBJECT(cop); \
74 opal_event_add(&cop->ev, 0); \
75 } while(0);
76
77 #define ORTE_RETRY_TCP_CONN_STATE(p, cbfunc, tv) \
78 do { \
79 mca_oob_tcp_conn_op_t *cop; \
80 opal_output_verbose(5, orte_oob_base_framework.framework_output, \
81 "%s:[%s:%d] retry connect to %s", \
82 ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), \
83 __FILE__, __LINE__, \
84 ORTE_NAME_PRINT((&(p)->name))); \
85 cop = OBJ_NEW(mca_oob_tcp_conn_op_t); \
86 cop->peer = (p); \
87 opal_event_evtimer_set((p)->ev_base, \
88 &cop->ev, \
89 (cbfunc), cop); \
90 ORTE_POST_OBJECT(cop); \
91 opal_event_evtimer_add(&cop->ev, (tv)); \
92 } while(0);
93
94 ORTE_MODULE_DECLSPEC void mca_oob_tcp_peer_try_connect(int fd, short args, void *cbdata);
95 ORTE_MODULE_DECLSPEC void mca_oob_tcp_peer_dump(mca_oob_tcp_peer_t* peer, const char* msg);
96 ORTE_MODULE_DECLSPEC bool mca_oob_tcp_peer_accept(mca_oob_tcp_peer_t* peer);
97 ORTE_MODULE_DECLSPEC void mca_oob_tcp_peer_complete_connect(mca_oob_tcp_peer_t* peer);
98 ORTE_MODULE_DECLSPEC int mca_oob_tcp_peer_recv_connect_ack(mca_oob_tcp_peer_t* peer,
99 int sd, mca_oob_tcp_hdr_t *dhdr);
100 ORTE_MODULE_DECLSPEC void mca_oob_tcp_peer_close(mca_oob_tcp_peer_t *peer);
101
102 #endif /* _MCA_OOB_TCP_CONNECTION_H_ */