Add Book to My BookshelfPurchase This Book Online

Chapter 15 - Networking with TLI

UNIX Systems Programming for SVR4
David A. Curry
 Copyright © 1996 O'Reilly & Associates, Inc.

TLI Utility Functions
Three utility functions are frequently used in conjunction with the rest of the TLI library:
    #include <tiuser.h>
    void t_error(const char *errmsg);
    char *t_alloc(int fd, int struct_type, int fields);
    int t_free(char *ptr, int struct_type);
The t_error function is used to print error messages when TLI functions fail. TLI functions set the external integer t_errno to an error code; t_error prints the string contained in errmsg, followed by an error message describing the error, to the standard error output. If the failure is due to a system error (as opposed to a library error), t_error also prints the system error message.
The t_alloc function can be used to allocate structures for use with the rest of the TLI library. The fd parameter is the transport endpoint (see below). The struct_type parameter specifies the type of structure to be allocated:
T_BIND
Allocate a struct t_bind structure.
T_CALL
Allocate a struct t_call structure.
T_DIS
Allocate a struct t_discon structure.
T_INFO
Allocate a struct t_info structure.
T_OPTMGMT
Allocate a struct t_optmgmt structure.
T_UDERROR
Allocate a struct t_uderror structure.
T_UNITDATA
Allocate a struct t_unitdata structure.
With the exception of the struct t_info structure, all of these structures contain one or more struct netbuf structures. The fields parameter is used to specify which, if any, of these buffers should be allocated as well. The fields parameter is the logical or of any of the following:
T_ADDR
Allocate the addr field of the t_bind, tcall, t_unitdata, or t_uderr structures.
T_OPT
Allocate the opt field of the t_optmgmt, t_call, t_unitdata, or t_uderr structures.
T_UDATA
Allocate the udata field of the t_call, t_discon, or t_unitdata structures.
T_ALL
Allocate all relevant fields of a given structure.
The t_alloc function allocates the buf portion of the struct netbuf structure, and sets the maxlen field appropriately. This frees the application from having to know how big a buffer needs to be for any particular purpose. If a structure cannot be allocated, t_alloc returns NULL. Otherwise, it returns a pointer to the allocated structure.
The t_free function frees the structure pointed to by ptr, which should have been allocated with t_alloc. The struct_type parameter specifies the type of structure, as described above for t_alloc. If one of the fields of the structure is NULL, t_alloc will not attempt to free it; in this way, partially allocated structures can be freed.

Previous SectionNext Section
Books24x7.com, Inc © 2000 –  Feedback