~ubuntu-branches/ubuntu/vivid/cctools/vivid

« back to all changes in this revision

Viewing changes to chirp/src/chirp_stream.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Hanke
  • Date: 2011-05-07 09:05:00 UTC
  • Revision ID: james.westby@ubuntu.com-20110507090500-lqpmdtwndor6e7os
Tags: upstream-3.3.2
ImportĀ upstreamĀ versionĀ 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (C) 2008- The University of Notre Dame
 
3
This software is distributed under the GNU General Public License.
 
4
See the file COPYING for details.
 
5
*/
 
6
 
 
7
#ifndef CHIRP_STREAM_H
 
8
#define CHIRP_STREAM_H
 
9
 
 
10
#include <sys/time.h>
 
11
#include <stdio.h>
 
12
 
 
13
/** @file chirp_stream.h
 
14
Streaming I/O interface.
 
15
This module implements <i>streaming I/O</i> against a Chirp server.
 
16
In this model, the user can read and write small amounts of data
 
17
in a continuous stream to or from a remote file.
 
18
This interface gives higher data throughput than the @ref chirp_reli.h
 
19
interface, but it is <i>unreliable</i>.  If a streaming connection is
 
20
lost, the client must close it and start all over again.  If reliability
 
21
is more important than performance, use the @ref chirp_reli.h interface instead.
 
22
*/
 
23
 
 
24
/** Indicates what mode to be used for opening a stream.*/
 
25
typedef enum {
 
26
        CHIRP_STREAM_READ,         /**< Open the stream for reading. */
 
27
        CHIRP_STREAM_WRITE,  /**< Open the stream for writing. */
 
28
} chirp_stream_mode_t;
 
29
 
 
30
/** Open a new stream for reading or writing.
 
31
Connects to a named server and creates a stream for reading or writing to the given file.
 
32
@param hostport The host and optional port number of the Chirp server.
 
33
@param path The pathname of the file to access.
 
34
@param mode The mode of the stream, either @ref CHIRP_STREAM_READ or @ref CHIRP_STREAM_WRITE.
 
35
@param stoptime The absolute time at which to abort.
 
36
@return On success, returns a handle to a chirp_stream.  On failure, returns zero and sets errno appropriately.
 
37
*/
 
38
 
 
39
struct chirp_stream * chirp_stream_open( const char *hostport, const char *path, chirp_stream_mode_t mode, time_t stoptime );
 
40
 
 
41
/** Print formatted data to a stream with buffering.
 
42
Writes formatted data to a stream, just like a standard Unix printf.
 
43
@param stream A stream created by @ref chirp_stream_open.
 
44
@param stoptime The absolute time at which to abort.
 
45
@param fmt A printf-style format string, followed by the data to transmit.
 
46
@return On success, returns the number of characters written to the stream.  On failure, returns less than zero and sets errno appropriately.
 
47
*/
 
48
 
 
49
int chirp_stream_printf( struct chirp_stream *stream, time_t stoptime, const char *fmt, ... );
 
50
 
 
51
/** Read a single line from a stream with buffering.
 
52
Reads a single line terminated by a linefeed (ASCII byte 10).  Carriage returns (ASCII byte 13) are ignored and removed from the input.
 
53
@param stream A stream created by @ref chirp_stream_open.
 
54
@param line A pointer to a buffer where the line can be placed.
 
55
@param length The size of the buffer in bytes.
 
56
@param stoptime The absolute time at which to abort.
 
57
@return On success, the number of bytes actually read.  On end-of-stream, returns zero.  On failure, returns less than zero and sets errno appropriately.
 
58
*/
 
59
int chirp_stream_readline( struct chirp_stream *stream, char *line, int length, time_t stoptime );
 
60
 
 
61
/** Write data to a stream.
 
62
@param stream A stream created by @ref chirp_stream_open.
 
63
@param data A pointer to a buffer of data to write.
 
64
@param length The size of the buffer in bytes.
 
65
@param stoptime The absolute time at which to abort.
 
66
@return On success, the number of bytes actually written.  On failure, returns less than zero and sets errno appropriately.
 
67
*/
 
68
 
 
69
int chirp_stream_write( struct chirp_stream *stream, const void *data, int length, time_t stoptime );
 
70
 
 
71
/** Read data from a stream.
 
72
@param stream A stream created by @ref chirp_stream_open.
 
73
@param data A pointer to a buffer where data can be placed.
 
74
@param length The size of the buffer in bytes.
 
75
@param stoptime The absolute time at which to abort.
 
76
@return On success, the number of bytes actually read.  On end-of-stream, returns zero. On failure, returns less than zero and sets errno appropriately.
 
77
*/
 
78
 
 
79
int chirp_stream_read( struct chirp_stream *stream, void *data, int length, time_t stoptime );
 
80
 
 
81
/** Flush buffered data to the stream.
 
82
@param stream A stream created by @ref chirp_stream_open.
 
83
@param stoptime The absolute time at which to abort.
 
84
@return On success, returns the number of characters written to the stream.  On failure, returns less than zero and sets errno appropriately.
 
85
*/
 
86
 
 
87
int chirp_stream_flush( struct chirp_stream *stream, time_t stoptime );
 
88
 
 
89
/** Closes a stream.
 
90
This routine closes and deallocates all state associated with a stream.
 
91
Note that a stream may buffer data internally, so the called does not know if all data has been written successfully unless this function returns success.
 
92
@param stream A stream created by @ref chirp_stream_open.
 
93
@param stoptime The absolute time at which to abort.
 
94
@return On success, returns greater than or equal to zero.  On failure, returns less than zero and sets errno appropriately.
 
95
*/
 
96
 
 
97
int chirp_stream_close( struct chirp_stream *stream, time_t stoptime );
 
98
 
 
99
#endif