Merge branch 'master' into mcb-tcp-xfer

This commit is contained in:
Michael Brown
2007-06-08 16:33:24 +01:00
27 changed files with 790 additions and 1044 deletions

View File

@@ -26,7 +26,9 @@ enum {
*
* Parameter list for open() is:
*
*
* int semantics;
* struct sockaddr *peer;
* struct sockaddr *local;
*/
LOCATION_SOCKET,
};
@@ -44,9 +46,6 @@ struct uri_opener {
* @v xfer Data transfer interface
* @v uri URI
* @ret rc Return status code
*
* This method takes ownership of the URI structure, and is
* responsible for eventually calling free_uri().
*/
int ( * open ) ( struct xfer_interface *xfer, struct uri *uri );
};
@@ -56,10 +55,10 @@ struct uri_opener {
/** A socket opener */
struct socket_opener {
/** Communication domain (e.g. PF_INET) */
int domain;
/** Communication semantics (e.g. SOCK_STREAM) */
int type;
int semantics;
/** Address family (e.g. AF_INET) */
int family;
/** Open socket
*
* @v xfer Data transfer interface
@@ -76,9 +75,11 @@ struct socket_opener {
extern int xfer_open_uri ( struct xfer_interface *xfer,
const char *uri_string );
extern int xfer_open_socket ( struct xfer_interface *xfer,
int domain, int type, struct sockaddr *peer,
struct sockaddr *local );
extern int xfer_open_named_socket ( struct xfer_interface *xfer,
int semantics, struct sockaddr *peer,
const char *name, struct sockaddr *local );
extern int xfer_open_socket ( struct xfer_interface *xfer, int semantics,
struct sockaddr *peer, struct sockaddr *local );
extern int xfer_vopen ( struct xfer_interface *xfer, int type, va_list args );
extern int xfer_open ( struct xfer_interface *xfer, int type, ... );

View File

@@ -8,6 +8,7 @@
*/
#include <gpxe/list.h>
#include <gpxe/refcnt.h>
/** A process */
struct process {
@@ -19,14 +20,46 @@ struct process {
* This method should execute a single step of the process.
* Returning from this method is isomorphic to yielding the
* CPU to another process.
*
* If the process wishes to be executed again, it must re-add
* itself to the run queue using schedule().
*/
void ( * step ) ( struct process *process );
/** Reference counter
*
* If this interface is not part of a reference-counted
* object, this field may be NULL.
*/
struct refcnt *refcnt;
};
extern void schedule ( struct process *process );
extern void process_add ( struct process *process );
extern void process_del ( struct process *process );
extern void step ( void );
/**
* Initialise process without adding to process list
*
* @v process Process
* @v step Process' step() method
*/
static inline __attribute__ (( always_inline )) void
process_init_stopped ( struct process *process,
void ( * step ) ( struct process *process ),
struct refcnt *refcnt ) {
process->step = step;
process->refcnt = refcnt;
}
/**
* Initialise process and add to process list
*
* @v process Process
* @v step Process' step() method
*/
static inline __attribute__ (( always_inline )) void
process_init ( struct process *process,
void ( * step ) ( struct process *process ),
struct refcnt *refcnt ) {
process_init_stopped ( process, step, refcnt );
process_add ( process );
}
#endif /* _GPXE_PROCESS_H */

View File

@@ -37,4 +37,15 @@ struct retry_timer {
extern void start_timer ( struct retry_timer *timer );
extern void stop_timer ( struct retry_timer *timer );
/**
* Test to see if timer is currently running
*
* @v timer Retry timer
* @ret running Non-zero if timer is running
*/
static inline __attribute__ (( always_inline )) unsigned long
timer_running ( struct retry_timer *timer ) {
return ( timer->start );
}
#endif /* _GPXE_RETRY_H */

View File

@@ -8,31 +8,7 @@
*/
/**
* @defgroup commdomains Communication domains
*
* @{
*/
#define PF_INET 1 /**< IPv4 Internet protocols */
#define PF_INET6 2 /**< IPv6 Internet protocols */
/** @} */
/**
* Name communication domain
*
* @v domain Communication domain (e.g. PF_INET)
* @ret name Name of communication domain
*/
static inline __attribute__ (( always_inline )) const char *
socket_domain_name ( int domain ) {
switch ( domain ) {
case PF_INET: return "PF_INET";
case PF_INET6: return "PF_INET6";
default: return "PF_UNKNOWN";
}
}
/**
* @defgroup commtypes Communication types
* @defgroup commtypes Communication semantics
*
* @{
*/
@@ -41,14 +17,14 @@ socket_domain_name ( int domain ) {
/** @} */
/**
* Name communication type
* Name communication semantics
*
* @v type Communication type (e.g. SOCK_STREAM)
* @ret name Name of communication type
* @v semantics Communication semantics (e.g. SOCK_STREAM)
* @ret name Name of communication semantics
*/
static inline __attribute__ (( always_inline )) const char *
socket_type_name ( int type ) {
switch ( type ) {
socket_semantics_name ( int semantics ) {
switch ( semantics ) {
case SOCK_STREAM: return "SOCK_STREAM";
case SOCK_DGRAM: return "SOCK_DGRAM";
default: return "SOCK_UNKNOWN";
@@ -64,6 +40,21 @@ socket_type_name ( int type ) {
#define AF_INET6 2 /**< IPv6 Internet addresses */
/** @} */
/**
* Name address family
*
* @v family Address family (e.g. AF_INET)
* @ret name Name of address family
*/
static inline __attribute__ (( always_inline )) const char *
socket_family_name ( int family ) {
switch ( family ) {
case AF_INET: return "AF_INET";
case AF_INET6: return "AF_INET6";
default: return "AF_UNKNOWN";
}
}
/** A socket address family */
typedef uint16_t sa_family_t;

View File

@@ -8,6 +8,7 @@
*/
#include <stdlib.h>
#include <gpxe/refcnt.h>
/** A Uniform Resource Identifier
*
@@ -37,6 +38,8 @@
* query = "what=is", fragment = "this"
*/
struct uri {
/** Reference count */
struct refcnt refcnt;
/** Scheme */
const char *scheme;
/** Opaque part */
@@ -100,18 +103,34 @@ static inline int uri_has_relative_path ( struct uri *uri ) {
}
/**
* Free URI structure
* Increment URI reference count
*
* @v uri URI
*
* Frees all the dynamically-allocated storage used by the URI
* structure.
* @ret uri URI
*/
static inline void free_uri ( struct uri *uri ) {
free ( uri );
static inline __attribute__ (( always_inline )) struct uri *
uri_get ( struct uri *uri ) {
ref_get ( &uri->refcnt );
return uri;
}
/**
* Decrement URI reference count
*
* @v uri URI
*/
static inline __attribute__ (( always_inline )) void
uri_put ( struct uri *uri ) {
ref_put ( &uri->refcnt );
}
extern struct uri * parse_uri ( const char *uri_string );
unsigned int uri_port ( struct uri *uri, unsigned int default_port );
extern unsigned int uri_port ( struct uri *uri, unsigned int default_port );
extern int unparse_uri ( char *buf, size_t size, struct uri *uri );
extern struct uri * uri_dup ( struct uri *uri );
extern char * resolve_path ( const char *base_path,
const char *relative_path );
extern struct uri * resolve_uri ( struct uri *base_uri,
struct uri *relative_uri );
#endif /* _GPXE_URI_H */

View File

@@ -64,4 +64,8 @@ struct printf_context {
extern size_t vcprintf ( struct printf_context *ctx, const char *fmt,
va_list args );
extern int vssnprintf ( char *buf, ssize_t ssize, const char *fmt,
va_list args );
extern int ssnprintf ( char *buf, ssize_t ssize, const char *fmt, ... );
#endif /* _GPXE_VSPRINTF_H */

View File

@@ -112,6 +112,20 @@ enum seek_whence {
SEEK_CUR,
};
/**
* Describe seek basis
*
* @v whence Basis for new position
*/
static inline __attribute__ (( always_inline )) const char *
whence_text ( int whence ) {
switch ( whence ) {
case SEEK_SET: return "SET";
case SEEK_CUR: return "CUR";
default: return "INVALID";
}
}
extern struct xfer_interface null_xfer;
extern struct xfer_interface_operations null_xfer_ops;
@@ -121,14 +135,18 @@ extern int xfer_vredirect ( struct xfer_interface *xfer, int type,
extern int xfer_redirect ( struct xfer_interface *xfer, int type, ... );
extern int xfer_request ( struct xfer_interface *xfer, off_t offset,
int whence, size_t len );
extern int xfer_request_all ( struct xfer_interface *xfer );
extern int xfer_seek ( struct xfer_interface *xfer, off_t offset, int whence );
extern int xfer_ready ( struct xfer_interface *xfer );
extern struct io_buffer * xfer_alloc_iob ( struct xfer_interface *xfer,
size_t len );
extern int xfer_deliver_iob ( struct xfer_interface *xfer,
struct io_buffer *iobuf );
extern int xfer_deliver_raw ( struct xfer_interface *xfer,
const void *data, size_t len );
extern int xfer_vprintf ( struct xfer_interface *xfer,
const char *format, va_list args );
extern int xfer_printf ( struct xfer_interface *xfer,
const char *format, ... );
extern void ignore_xfer_close ( struct xfer_interface *xfer, int rc );
extern int ignore_xfer_vredirect ( struct xfer_interface *xfer,

View File

@@ -1,6 +1,7 @@
#ifndef _LIBGEN_H
#define _LIBGEN_H
char * basename ( char *path );
extern char * basename ( char *path );
extern char * dirname ( char *path );
#endif /* _LIBGEN_H */

View File

@@ -10,10 +10,15 @@ printf ( const char *fmt, ... );
extern int __attribute__ (( format ( printf, 3, 4 ) ))
snprintf ( char *buf, size_t size, const char *fmt, ... );
extern int __attribute__ (( format ( printf, 2, 3 ) ))
asprintf ( char **strp, const char *fmt, ... );
extern int vprintf ( const char *fmt, va_list args );
extern int vsnprintf ( char *buf, size_t size, const char *fmt, va_list args );
extern int vasprintf ( char **strp, const char *fmt, va_list args );
/**
* Write a formatted string to a buffer
*