1 /*****************************************************************************
2 * Copyright 2005 Daniel Ferullo *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
16 *****************************************************************************/
20 * @author Daniel Ferullo (ferullo@.cmu.edu)
22 * @brief provides functions to do read/write from/to a socket
30 #include "errorcodes.h"
35 * @brief reads up to buf_len bytes into buf
37 * This function checks that as it read messages the length field of the header
40 * THIS FUNCTION CONTAINS A COMPLICATED WHILE LOOP THAT IS WORTH A SECOND LOOK!
42 * @param sd the socket to read from
43 * @param type the message type to read
44 * @param buf the buffer to store the message in (the payload only)
45 * @param buf_len the length of the buffer
47 * @return SUCCESS, errorcode on failure
49 errorcode
readMsg(sock_t sd
, comm_type_t type
, void* buf
, int buf_len
);
52 * @brief creates a message from the type and payload and sents it
54 * @param sd the socket to send on
55 * @param type the message type
56 * @param payload a pointer to the payload (can be NULL if payload == 0)
57 * @param payload_len the length of the payload in bytes
59 * @return SUCCESS, neg on failure
61 errorcode
sendMsg(sock_t sd
, long type
, void* payload
, long payload_len
);
63 #endif /* __NETIO_H__ */