ccn_fetch.c File Reference

Go to the source code of this file.

Defines

#define CCN_VERSION_TIMEOUT   8000
 Streaming access for fetching segmented CCNx data.
#define CCN_INTEREST_TIMEOUT_USECS   15000000
#define MaxSuffixDefault   4

Typedefs

typedef intmax_t seg_t
typedef uint64_t TimeMarker

Functions

static TimeMarker GetCurrentTimeUSecs (void)
static intmax_t DeltaTime (TimeMarker mt1, TimeMarker mt2)
static enum ccn_upcall_res CallMe (struct ccn_closure *selfp, enum ccn_upcall_kind kind, struct ccn_upcall_info *info)
static char * newStringCopy (const char *src)
static char * freeString (char *s)
static struct ccn_charbufsequenced_name (struct ccn_charbuf *basename, seg_t seq)
static struct ccn_charbufmake_data_template (int maxSuffix)
static seg_t GetNumberFromInfo (const unsigned char *ccnb, enum ccn_dtag tt, size_t start, size_t stop)
static seg_t GetFinalSegment (struct ccn_upcall_info *info)
static struct localClosure * AddSegRequest (struct ccn_fetch_stream *fs, seg_t seg)
static struct localClosure * RemSegRequest (struct ccn_fetch_stream *fs, struct localClosure *req)
static struct ccn_fetch_buffer * FindBufferForSeg (struct ccn_fetch_stream *fs, seg_t seg)
static struct ccn_fetch_buffer * FindBufferForPosition (struct ccn_fetch_stream *fs, intmax_t pos)
static intmax_t InferPosition (struct ccn_fetch_stream *fs, seg_t seg)
static struct ccn_fetch_buffer * NewBufferForSeg (struct ccn_fetch_stream *fs, seg_t seg, size_t len)
static void PruneSegments (struct ccn_fetch_stream *fs)
static void NeedSegment (struct ccn_fetch_stream *fs, seg_t seg)
static void NeedSegments (struct ccn_fetch_stream *fs)
static void ShowDelta (FILE *f, TimeMarker from)
struct ccn_fetch * ccn_fetch_new (struct ccn *h)
 Creates a new ccn_fetch object using the given ccn connection.
void ccn_fetch_set_debug (struct ccn_fetch *f, FILE *debug, ccn_fetch_flags flags)
 Sets the destination for debug output.
struct ccn_fetch * ccn_fetch_destroy (struct ccn_fetch *f)
 Destroys a ccn_fetch object.
int ccn_fetch_poll (struct ccn_fetch *f)
 Polls the underlying streams and attempts to make progress.
struct ccn_fetch_stream * ccn_fetch_next (struct ccn_fetch *f, struct ccn_fetch_stream *fs)
 Provides an iterator through the underlying streams.
struct ccn * ccn_fetch_get_ccn (struct ccn_fetch *f)
struct ccn_fetch_stream * ccn_fetch_open (struct ccn_fetch *f, struct ccn_charbuf *name, const char *id, struct ccn_charbuf *interestTemplate, int maxBufs, int resolveVersion, int assumeFixed)
 Creates a stream for a named interest.
struct ccn_fetch_stream * ccn_fetch_close (struct ccn_fetch_stream *fs)
 Closes the stream and reclaims any resources used by the stream.
intmax_t ccn_fetch_avail (struct ccn_fetch_stream *fs)
 Tests for available bytes in the stream.
intmax_t ccn_fetch_read (struct ccn_fetch_stream *fs, void *buf, intmax_t len)
 Reads bytes from a stream.
void ccn_reset_timeout (struct ccn_fetch_stream *fs)
 Resets the timeout marker.
int ccn_fetch_seek (struct ccn_fetch_stream *fs, intmax_t pos)
 Seeks to a position in a stream.
intmax_t ccn_fetch_position (struct ccn_fetch_stream *fs)

Variables

static char * globalNullString = ""


Define Documentation

#define CCN_INTEREST_TIMEOUT_USECS   15000000

Definition at line 49 of file ccn_fetch.c.

Referenced by ccn_fetch_open().

#define CCN_VERSION_TIMEOUT   8000

Streaming access for fetching segmented CCNx data.

Supports multiple streams from a single connection and seeking to an arbitrary position within the associated file.

TBD: need to fix up the case where a segment cannot be fetched but we are not really at the end of the stream data. This case can occur if we express an interest for a segment and the interest times out. Current behavior is to treat this as an end-of-stream (prematurely and silently)

TBD: need to provide a more principled (or maybe just controlled) way to handle interest timeouts.

Definition at line 48 of file ccn_fetch.c.

Referenced by ccn_fetch_open().

#define MaxSuffixDefault   4

Definition at line 50 of file ccn_fetch.c.

Referenced by ccn_fetch_open().


Typedef Documentation

typedef intmax_t seg_t

Definition at line 52 of file ccn_fetch.c.

typedef uint64_t TimeMarker

Definition at line 54 of file ccn_fetch.c.


Function Documentation

static struct localClosure* AddSegRequest ( struct ccn_fetch_stream *  fs,
seg_t  seg 
) [static, read]

Definition at line 213 of file ccn_fetch.c.

Referenced by NeedSegment().

static enum ccn_upcall_res CallMe ( struct ccn_closure selfp,
enum ccn_upcall_kind  kind,
struct ccn_upcall_info info 
) [static]

Definition at line 467 of file ccn_fetch.c.

Referenced by NeedSegment().

intmax_t ccn_fetch_avail ( struct ccn_fetch_stream *  fs  ) 

Tests for available bytes in the stream.

Determines how many bytes can be read on the given stream without waiting (via ccn_fetch_poll).

Returns:
CCN_FETCH_READ_TIMEOUT if a timeout occurred, CCN_FETCH_READ_ZERO if a zero-length segment was found CCN_FETCH_READ_NONE if no bytes are immediately available CCN_FETCH_READ_END if the stream is at the end, and N > 0 if N bytes can be read without performing a poll.

Definition at line 905 of file ccn_fetch.c.

Referenced by ccn_fetch_poll(), and getFile().

struct ccn_fetch_stream* ccn_fetch_close ( struct ccn_fetch_stream *  fs  )  [read]

Closes the stream and reclaims any resources used by the stream.

The stream object will be freed, so the client must not access it again.

Returns:
NULL in all cases.

Definition at line 845 of file ccn_fetch.c.

Referenced by ccn_fetch_destroy(), ElemDone(), getFile(), and main().

struct ccn_fetch* ccn_fetch_destroy ( struct ccn_fetch *  f  )  [read]

Destroys a ccn_fetch object.

Only destroys the underlying ccn connection if it was automatically created. Forces all underlying streams to close immediately.

Returns:
NULL in all cases.

Definition at line 662 of file ccn_fetch.c.

Referenced by getFile(), and main().

struct ccn* ccn_fetch_get_ccn ( struct ccn_fetch *  f  )  [read]

Returns:
the underlying ccn connection.

Definition at line 738 of file ccn_fetch.c.

struct ccn_fetch* ccn_fetch_new ( struct ccn *  h  )  [read]

Creates a new ccn_fetch object using the given ccn connection.

If h == NULL, attempts to create a new connection automatically.

Returns:
NULL if the creation was not successful (only can happen for the h == NULL case).

Definition at line 633 of file ccn_fetch.c.

Referenced by getFile(), and main().

struct ccn_fetch_stream* ccn_fetch_next ( struct ccn_fetch *  f,
struct ccn_fetch_stream *  fs 
) [read]

Provides an iterator through the underlying streams.

Use fs == NULL to start the iteration, and an existing stream to continue the iteration.

Returns:
the next stream in the iteration, or NULL at the end. Note that providing a stale (closed) stream handle will return NULL.

Definition at line 720 of file ccn_fetch.c.

struct ccn_fetch_stream* ccn_fetch_open ( struct ccn_fetch *  f,
struct ccn_charbuf name,
const char *  id,
struct ccn_charbuf interestTemplate,
int  maxBufs,
int  resolveVersion,
int  assumeFixed 
) [read]

Creates a stream for a named interest.

The name should be a ccnb encoded interest. If resolveVersion, then we assume that the version is unresolved, and an attempt is made to determine the version number using the highest version. The number of buffers (nBufs) may be silently limited.

Returns:
NULL if the stream creation failed, otherwise returns the new stream.

Definition at line 753 of file ccn_fetch.c.

Referenced by getFile(), main(), and NewElem().

int ccn_fetch_poll ( struct ccn_fetch *  f  ) 

Polls the underlying streams and attempts to make progress.

Scans the streams for those that have data already present, or are at the end of the stream. If the count is 0, perfoms a ccn_poll on the underlying ccn connection with a 0 timeout.

NOTE: periodic calls to ccn_fetch_poll should be performed to update the contents of the streams UNLESS the client is calling ccn_run for the underlying ccn connection.

Returns:
the count of streams that have pending data or have ended.

Definition at line 696 of file ccn_fetch.c.

Referenced by runTest().

intmax_t ccn_fetch_position ( struct ccn_fetch_stream *  fs  ) 

Returns:
the current read position.

Definition at line 1092 of file ccn_fetch.c.

intmax_t ccn_fetch_read ( struct ccn_fetch_stream *  fs,
void *  buf,
intmax_t  len 
)

Reads bytes from a stream.

Reads at most len bytes into buf from the given stream. Will not wait for bytes to arrive. Advances the read position on a successful read.

Returns:
CCN_FETCH_READ_TIMEOUT if a timeout occurred, CCN_FETCH_READ_ZERO if a zero-length segment was found CCN_FETCH_READ_NONE if no bytes are immediately available CCN_FETCH_READ_END if the stream is at the end, and N > 0 if N bytes were read.

Definition at line 957 of file ccn_fetch.c.

Referenced by getFile(), main(), and runTest().

int ccn_fetch_seek ( struct ccn_fetch_stream *  fs,
intmax_t  pos 
)

Seeks to a position in a stream.

Sets the read position. It is strongly recommended that the seek is only done to a position that is either 0 or has resulted from a successful read. Otherwise end of stream indicators may be returned for a seek beyond the end.

Returns:
-1 if the seek is to a bad position, otherwise returns 0.

Definition at line 1044 of file ccn_fetch.c.

void ccn_fetch_set_debug ( struct ccn_fetch *  f,
FILE *  debug,
ccn_fetch_flags  flags 
)

Sets the destination for debug output.

NULL disables debug output.

Definition at line 650 of file ccn_fetch.c.

Referenced by getFile(), and main().

void ccn_reset_timeout ( struct ccn_fetch_stream *  fs  ) 

Resets the timeout marker.

Resets the timeout indicator, which will cause pending interests to be retried.

Definition at line 1030 of file ccn_fetch.c.

Referenced by main(), and runTest().

static intmax_t DeltaTime ( TimeMarker  mt1,
TimeMarker  mt2 
) [static]

Definition at line 65 of file ccn_fetch.c.

Referenced by CallMe(), ElemDone(), and ShowDelta().

static struct ccn_fetch_buffer* FindBufferForPosition ( struct ccn_fetch_stream *  fs,
intmax_t  pos 
) [static, read]

Definition at line 290 of file ccn_fetch.c.

Referenced by ccn_fetch_seek().

static struct ccn_fetch_buffer* FindBufferForSeg ( struct ccn_fetch_stream *  fs,
seg_t  seg 
) [static, read]

static char* freeString ( char *  s  )  [static]

Definition at line 144 of file ccn_fetch.c.

Referenced by ccn_fetch_close(), and ccn_fetch_open().

static TimeMarker GetCurrentTimeUSecs ( void   )  [static]

Definition at line 57 of file ccn_fetch.c.

Referenced by AddSegRequest(), CallMe(), and ShowDelta().

static seg_t GetFinalSegment ( struct ccn_upcall_info info  )  [static]

Definition at line 200 of file ccn_fetch.c.

Referenced by CallMe().

static seg_t GetNumberFromInfo ( const unsigned char *  ccnb,
enum ccn_dtag  tt,
size_t  start,
size_t  stop 
) [static]

Definition at line 176 of file ccn_fetch.c.

Referenced by GetFinalSegment().

static intmax_t InferPosition ( struct ccn_fetch_stream *  fs,
seg_t  seg 
) [static]

Definition at line 303 of file ccn_fetch.c.

Referenced by CallMe(), and NewBufferForSeg().

static struct ccn_charbuf* make_data_template ( int  maxSuffix  )  [static, read]

Definition at line 161 of file ccn_fetch.c.

Referenced by ccn_fetch_open().

static void NeedSegment ( struct ccn_fetch_stream *  fs,
seg_t  seg 
) [static]

Definition at line 385 of file ccn_fetch.c.

Referenced by ccn_fetch_open(), ccn_fetch_seek(), and NeedSegments().

static void NeedSegments ( struct ccn_fetch_stream *  fs  )  [static]

Definition at line 444 of file ccn_fetch.c.

Referenced by ccn_fetch_read().

static struct ccn_fetch_buffer* NewBufferForSeg ( struct ccn_fetch_stream *  fs,
seg_t  seg,
size_t  len 
) [static, read]

Definition at line 324 of file ccn_fetch.c.

Referenced by CallMe().

static char* newStringCopy ( const char *  src  )  [static]

Definition at line 135 of file ccn_fetch.c.

Referenced by ccn_fetch_open().

static void PruneSegments ( struct ccn_fetch_stream *  fs  )  [static]

Definition at line 359 of file ccn_fetch.c.

Referenced by ccn_fetch_close(), ccn_fetch_read(), and ccn_fetch_seek().

static struct localClosure* RemSegRequest ( struct ccn_fetch_stream *  fs,
struct localClosure *  req 
) [static, read]

Definition at line 241 of file ccn_fetch.c.

Referenced by CallMe(), and NeedSegment().

static struct ccn_charbuf* sequenced_name ( struct ccn_charbuf basename,
seg_t  seq 
) [static, read]

Definition at line 151 of file ccn_fetch.c.

Referenced by ask_more(), fill_holes(), and NeedSegment().

static void ShowDelta ( FILE *  f,
TimeMarker  from 
) [static]

Definition at line 460 of file ccn_fetch.c.

Referenced by CallMe().


Variable Documentation

char* globalNullString = "" [static]

Definition at line 133 of file ccn_fetch.c.

Referenced by freeString(), and newStringCopy().


Generated on Thu Feb 16 00:44:22 2012 for Content-Centric Networking in C by  doxygen 1.5.6