1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2002 Cray Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 This file implements the TCP-based nal by providing glue
24 between the connection service and the generic NAL implementation */
31 #include <sys/types.h>
32 #include <sys/socket.h>
33 #include <netinet/in.h>
38 #include <connection.h>
40 /* Function: tcpnal_send
41 * Arguments: nal: pointer to my nal control block
43 * cookie: passed back to the portals library
44 * hdr: pointer to the portals header
45 * nid: destination node
46 * pid: destination process
47 * data: body of the message
48 * len: length of the body
49 * Returns: zero on success
51 * sends a packet to the peer, after insuring that a connection exists
53 #warning FIXME: "param 'type' is newly added, make use of it!!"
54 int tcpnal_send(nal_cb_t *n,
66 bridge b=(bridge)n->nal_data;
70 if (!(c=force_tcp_connection((manager)b->lower,
76 /* TODO: these results should be checked. furthermore, provision
77 must be made for the SIGPIPE which is delivered when
78 writing on a tcp socket which has closed underneath
79 the application. there is a linux flag in the sendmsg
80 call which turns off the signally behaviour, but its
82 syscall(SYS_write, c->fd,hdr,sizeof(ptl_hdr_t));
84 if (len) syscall(SYS_write, c->fd,iov[0].iov_base,len);
88 tiov[0].iov_base = hdr;
89 tiov[0].iov_len = sizeof(ptl_hdr_t);
92 tiov[1].iov_base = iov[0].iov_base;
93 tiov[1].iov_len = len;
97 syscall(SYS_writev, c->fd, tiov, count);
99 lib_finalize(n, private, cookie);
105 /* Function: tcpnal_recv
106 * Arguments: nal_cb_t *nal: pointer to my nal control block
107 * void *private: connection pointer passed through
109 * lib_msg_t *cookie: passed back to portals library
110 * user_ptr data: pointer to the destination buffer
111 * size_t mlen: length of the body
112 * size_t rlen: length of data in the network
113 * Returns: zero on success
115 * blocking read of the requested data. must drain out the
116 * difference of mainpulated and requested lengths from the network
118 int tcpnal_recv(nal_cb_t *n,
129 read_connection(private,iov[0].iov_base,mlen);
130 lib_finalize(n, private, cookie);
134 char *trash=malloc(rlen-mlen);
136 /*TODO: check error status*/
137 read_connection(private,trash,rlen-mlen);
145 /* Function: from_connection:
146 * Arguments: c: the connection to read from
147 * Returns: whether or not to continue reading from this connection,
148 * expressed as a 1 to continue, and a 0 to not
150 * from_connection() is called from the select loop when i/o is
151 * available. It attempts to read the portals header and
152 * pass it to the generic library for processing.
154 static int from_connection(void *a, void *d)
160 if (read_connection(c, (unsigned char *)&hdr, sizeof(hdr))){
161 lib_parse(b->nal_cb, &hdr, c);
168 static void tcpnal_shutdown(bridge b)
170 shutdown_connections(b->lower);
173 /* Function: PTL_IFACE_TCP
174 * Arguments: pid_request: desired port number to bind to
175 * desired: passed NAL limits structure
176 * actual: returned NAL limits structure
177 * Returns: a nal structure on success, or null on failure
179 int tcpnal_init(bridge b)
183 b->nal_cb->cb_send=tcpnal_send;
184 b->nal_cb->cb_recv=tcpnal_recv;
185 b->shutdown=tcpnal_shutdown;
187 if (!(m=init_connections(PNAL_PORT(b->nal_cb->ni.nid,
189 from_connection,b))){
190 /* TODO: this needs to shut down the
191 newly created junk */
192 return(PTL_NAL_FAILED);