Annotation of libwww/Library/src/HTLocal.c, revision 2.6
2.1 frystyk 1: /* HTLocal.c
2: ** LOCAL FILE HANDLING
3: **
4: ** (c) COPYRIGHT MIT 1995.
5: ** Please first read the full copyright statement in the file COPYRIGH.
2.6 ! frystyk 6: ** @(#) $Id: HTLocal.c,v 2.5 1996/12/07 00:06:27 eric Exp $
2.1 frystyk 7: **
8: ** History:
9: ** HFN: Written
10: */
11:
12: /* Library include files */
13: #include "sysdep.h"
14: #include "WWWUtil.h"
15: #include "HTAlert.h"
16: #include "HTParse.h"
17: #include "HTReq.h"
18: #include "HTNetMan.h"
2.4 frystyk 19: #include "HTHstMan.h"
2.1 frystyk 20: #include "HTError.h"
21: #include "HTLocal.h" /* Implemented here */
22:
23: /* ------------------------------------------------------------------------- */
24:
25: /*
2.2 frystyk 26: ** Opens a local file usien whatever means are available on the current
27: ** platform. If we have unix file descriptors then use that as we can use
28: ** select on them. Otherwise use ANSI C file descriptors.
2.1 frystyk 29: **
2.2 frystyk 30: ** returns HT_ERROR Error has occured or interrupted
31: ** HT_OK if connected
32: ** HT_WOULD_BLOCK if operation would have blocked
2.1 frystyk 33: */
34: PUBLIC int HTFileOpen (HTNet * net, char * local, HTLocalMode mode)
35: {
36: HTRequest * request = net->request;
2.4 frystyk 37: SOCKET sockfd = INVSOC;
2.1 frystyk 38: #ifndef NO_UNIX_IO
2.2 frystyk 39: int status = -1; /* JTD:5/30/96 - must init status to -1 */
2.4 frystyk 40: if ((sockfd = open(local, mode)) == -1) {
2.1 frystyk 41: HTRequest_addSystemError(request, ERR_FATAL, errno, NO, "open");
42: return HT_ERROR;
43: }
44:
45: /* If non-blocking protocol then change socket status
46: ** I use fcntl() so that I can ask the status before I set it.
47: ** See W. Richard Stevens (Advan. Prog. in UNIX env, p.364)
48: ** Be CAREFULL with the old `O_NDELAY' - it wont work as read()
49: ** returns 0 when blocking and NOT -1. FNDELAY is ONLY for BSD
50: ** and does NOT work on SVR4 systems. O_NONBLOCK is POSIX.
51: */
52: if (!net->preemptive) {
53: #ifdef HAVE_FCNTL
2.4 frystyk 54: if ((status = fcntl(HTNet_socket(net), F_GETFL, 0)) != -1) {
2.1 frystyk 55: #ifdef O_NONBLOCK
2.2 frystyk 56: status |= O_NONBLOCK;/* POSIX */
2.1 frystyk 57: #else
58: #ifdef F_NDELAY
2.2 frystyk 59: status |= F_NDELAY; /* BSD */
2.1 frystyk 60: #endif /* F_NDELAY */
61: #endif /* O_NONBLOCK */
2.4 frystyk 62: status = fcntl(HTNet_socket(net), F_SETFL, status);
2.1 frystyk 63: }
2.2 frystyk 64: #endif /* HAVE_FCNTL */
2.1 frystyk 65: if (PROT_TRACE)
66: HTTrace("HTFileOpen.. `%s\' opened using %sblocking socket\n",
67: local, status == -1 ? "" : "NON-");
68: }
2.2 frystyk 69: /* #endif - HAVE_FCNTL <- wrong location, moved up JTD:5/30/96 */
70: #else /* !NO_UNIX_IO */
2.1 frystyk 71: #ifdef VMS
2.6 ! frystyk 72: if (!(net->host->fp = fopen(local, mode,"shr=put","shr=upd"))) {
2.1 frystyk 73: HTRequest_addSystemError(request, ERR_FATAL, errno, NO, "fopen");
74: return HT_ERROR;
75: }
76: #else
2.5 eric 77: if ((net->host->fp = fopen(local, mode)) == NULL) {
2.2 frystyk 78: HTRequest_addSystemError(request, ERR_FATAL, errno, NO, "fopen");
79: return HT_ERROR;
2.1 frystyk 80: }
81: #endif /* VMS */
82: if (PROT_TRACE)
2.5 eric 83: HTTrace("HTDoOpen.... `%s\' opened using FILE %p\n",local, net->host->fp);
2.1 frystyk 84: #endif /* !NO_UNIX_IO */
2.4 frystyk 85:
86: /*
87: ** Associate the channel with the host and create an input and and output stream
88: ** for this host/channel
89: */
90: HTHost_setChannel(net->host, HTChannel_new(sockfd, YES));
91: HTHost_getInput(net->host, net->transport, NULL, 0);
92: HTHost_getOutput(net->host, net->transport, NULL, 0);
93:
2.1 frystyk 94: return HT_OK;
95: }
96:
97: /*
98: ** Closes a file descriptor whatever means are available on the current
99: ** platform. If we have unix file descriptors then use this otherwise use
100: ** the ANSI C file descriptors
101: **
102: ** returns HT_ERROR Error has occured or interrupted
103: ** HT_OK if connected
104: ** HT_WOULD_BLOCK if operation would have blocked
105: */
2.3 frystyk 106: PUBLIC int HTFileClose (HTNet * net)
2.1 frystyk 107: {
108: int status = -1;
109: if (net) {
2.5 eric 110: #ifdef NO_UNIX_IO
2.4 frystyk 111: if (net->host->fp) {
112: if (PROT_TRACE) HTTrace("Closing..... ANSI file %p\n", net->host->fp);
113: status = fclose(net->host->fp);
114: net->host->fp = NULL;
2.1 frystyk 115: }
116: #else
2.4 frystyk 117: if (HTNet_socket(net) != INVSOC) {
118: if (PROT_TRACE) HTTrace("Closing..... fd %d\n", HTNet_socket(net));
119: status = NETCLOSE(HTNet_socket(net));
2.5 eric 120: HTNet_setSocket(net, INVSOC);
2.1 frystyk 121: }
122: #endif /* NO_UNIX_IO */
123: }
124: return status < 0 ? HT_ERROR : HT_OK;
125: }
126:
Webmaster