Main Page | Data Structures | File List | Data Fields | Globals | Related Pages

netio.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Copyright 2005 Daniel Ferullo                                             *
00003  *                                                                           *
00004  * Licensed under the Apache License, Version 2.0 (the "License");           *
00005  * you may not use this file except in compliance with the License.          *
00006  * You may obtain a copy of the License at                                   *
00007  *                                                                           *
00008  *    http://www.apache.org/licenses/LICENSE-2.0                             *
00009  *                                                                           *
00010  * Unless required by applicable law or agreed to in writing, software       *
00011  * distributed under the License is distributed on an "AS IS" BASIS,         *
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  *
00013  * See the License for the specific language governing permissions and       *
00014  * limitations under the License.                                            *
00015  *                                                                           *
00016  *****************************************************************************/
00017 
00018 /**
00019  * @file netio.h
00020  * @author Daniel Ferullo (ferullo@.cmu.edu)
00021  *
00022  * @brief provides functions to do read/write from/to a socket
00023  */
00024 
00025 #ifndef __NETIO_H__
00026 #define __NETIO_H__
00027 
00028 #include <stdio.h>
00029 
00030 #include "errorcodes.h"
00031 #include "comm.h"
00032 #include "def.h"
00033 
00034 /**
00035  * @brief reads up to buf_len bytes into buf
00036  *
00037  * This function checks that as it read messages the length field of the header
00038  * is correct
00039  *
00040  * THIS FUNCTION CONTAINS A COMPLICATED WHILE LOOP THAT IS WORTH A SECOND LOOK!
00041  *
00042  * @param sd the socket to read from
00043  * @param type the message type to read
00044  * @param buf the buffer to store the message in (the payload only)
00045  * @param buf_len the length of the buffer
00046  *
00047  * @return SUCCESS, errorcode on failure
00048  */
00049 errorcode readMsg(sock_t sd, comm_type_t type, void* buf, int buf_len);
00050 
00051 /**
00052  * @brief creates a message from the type and payload and sents it
00053  *
00054  * @param sd the socket to send on
00055  * @param type the message type
00056  * @param payload a pointer to the payload (can be NULL if payload == 0)
00057  * @param payload_len the length of the payload in bytes
00058  *
00059  * @return SUCCESS, neg on failure
00060  */
00061 errorcode sendMsg(sock_t sd, long type, void* payload, long payload_len);
00062 
00063 #endif /* __NETIO_H__ */

Generated on Wed Mar 30 23:20:47 2005 for NATBLASTER by  doxygen 1.3.9.1