/[dtapublic]/projs/trunk/shared_source/c_tcl_base_7_5_w_mods/tcliosock.c
ViewVC logotype

Diff of /projs/trunk/shared_source/c_tcl_base_7_5_w_mods/tcliosock.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 64 by dashley, Sun Oct 30 04:21:11 2016 UTC revision 71 by dashley, Sat Nov 5 11:07:06 2016 UTC
# Line 1  Line 1 
1  /*$Header$ */  /* $Header$ */
2  /*  /*
3   * tclIOSock.c --   * tclIOSock.c --
4   *   *
5   *      Common routines used by all socket based channel types.   *      Common routines used by all socket based channel types.
6   *   *
7   * Copyright (c) 1995-1997 Sun Microsystems, Inc.   * Copyright (c) 1995-1997 Sun Microsystems, Inc.
8   *   *
9   * See the file "license.terms" for information on usage and redistribution   * See the file "license.terms" for information on usage and redistribution
10   * of this file, and for a DISCLAIMER OF ALL WARRANTIES.   * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11   *   *
12   * RCS: @(#) $Id: tcliosock.c,v 1.1.1.1 2001/06/13 04:42:17 dtashley Exp $   * RCS: @(#) $Id: tcliosock.c,v 1.1.1.1 2001/06/13 04:42:17 dtashley Exp $
13   */   */
14    
15  #include "tclInt.h"  #include "tclInt.h"
16  #include "tclPort.h"  #include "tclPort.h"
17    
18  /*  /*
19   *---------------------------------------------------------------------------   *---------------------------------------------------------------------------
20   *   *
21   * TclSockGetPort --   * TclSockGetPort --
22   *   *
23   *      Maps from a string, which could be a service name, to a port.   *      Maps from a string, which could be a service name, to a port.
24   *      Used by socket creation code to get port numbers and resolve   *      Used by socket creation code to get port numbers and resolve
25   *      registered service names to port numbers.   *      registered service names to port numbers.
26   *   *
27   * Results:   * Results:
28   *      A standard Tcl result.  On success, the port number is returned   *      A standard Tcl result.  On success, the port number is returned
29   *      in portPtr. On failure, an error message is left in the interp's   *      in portPtr. On failure, an error message is left in the interp's
30   *      result.   *      result.
31   *   *
32   * Side effects:   * Side effects:
33   *      None.   *      None.
34   *   *
35   *---------------------------------------------------------------------------   *---------------------------------------------------------------------------
36   */   */
37    
38  int  int
39  TclSockGetPort(interp, string, proto, portPtr)  TclSockGetPort(interp, string, proto, portPtr)
40      Tcl_Interp *interp;      Tcl_Interp *interp;
41      char *string;               /* Integer or service name */      char *string;               /* Integer or service name */
42      char *proto;                /* "tcp" or "udp", typically */      char *proto;                /* "tcp" or "udp", typically */
43      int *portPtr;               /* Return port number */      int *portPtr;               /* Return port number */
44  {  {
45      struct servent *sp;         /* Protocol info for named services */      struct servent *sp;         /* Protocol info for named services */
46      Tcl_DString ds;      Tcl_DString ds;
47      char *native;      char *native;
48    
49      if (Tcl_GetInt(NULL, string, portPtr) != TCL_OK) {      if (Tcl_GetInt(NULL, string, portPtr) != TCL_OK) {
50          /*          /*
51           * Don't bother translating 'proto' to native.           * Don't bother translating 'proto' to native.
52           */           */
53                    
54          native = Tcl_UtfToExternalDString(NULL, string, -1, &ds);          native = Tcl_UtfToExternalDString(NULL, string, -1, &ds);
55          sp = getservbyname(native, proto);              /* INTL: Native. */          sp = getservbyname(native, proto);              /* INTL: Native. */
56          Tcl_DStringFree(&ds);          Tcl_DStringFree(&ds);
57          if (sp != NULL) {          if (sp != NULL) {
58              *portPtr = ntohs((unsigned short) sp->s_port);              *portPtr = ntohs((unsigned short) sp->s_port);
59              return TCL_OK;              return TCL_OK;
60          }          }
61      }      }
62      if (Tcl_GetInt(interp, string, portPtr) != TCL_OK) {      if (Tcl_GetInt(interp, string, portPtr) != TCL_OK) {
63          return TCL_ERROR;          return TCL_ERROR;
64      }      }
65      if (*portPtr > 0xFFFF) {      if (*portPtr > 0xFFFF) {
66          Tcl_AppendResult(interp, "couldn't open socket: port number too high",          Tcl_AppendResult(interp, "couldn't open socket: port number too high",
67                  (char *) NULL);                  (char *) NULL);
68          return TCL_ERROR;          return TCL_ERROR;
69      }      }
70      return TCL_OK;      return TCL_OK;
71  }  }
72    
73  /*  /*
74   *----------------------------------------------------------------------   *----------------------------------------------------------------------
75   *   *
76   * TclSockMinimumBuffers --   * TclSockMinimumBuffers --
77   *   *
78   *      Ensure minimum buffer sizes (non zero).   *      Ensure minimum buffer sizes (non zero).
79   *   *
80   * Results:   * Results:
81   *      A standard Tcl result.   *      A standard Tcl result.
82   *   *
83   * Side effects:   * Side effects:
84   *      Sets SO_SNDBUF and SO_RCVBUF sizes.   *      Sets SO_SNDBUF and SO_RCVBUF sizes.
85   *   *
86   *----------------------------------------------------------------------   *----------------------------------------------------------------------
87   */   */
88    
89  int  int
90  TclSockMinimumBuffers(sock, size)  TclSockMinimumBuffers(sock, size)
91      int sock;                   /* Socket file descriptor */      int sock;                   /* Socket file descriptor */
92      int size;                   /* Minimum buffer size */      int size;                   /* Minimum buffer size */
93  {  {
94      int current;      int current;
95      /*      /*
96       * Should be socklen_t, but HP10.20 (g)cc chokes       * Should be socklen_t, but HP10.20 (g)cc chokes
97       */       */
98      size_t len;      size_t len;
99    
100      len = sizeof(int);      len = sizeof(int);
101      getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *)&current, &len);      getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *)&current, &len);
102      if (current < size) {      if (current < size) {
103          len = sizeof(int);          len = sizeof(int);
104          setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *)&size, len);          setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *)&size, len);
105      }      }
106      len = sizeof(int);      len = sizeof(int);
107      getsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *)&current, &len);      getsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *)&current, &len);
108      if (current < size) {      if (current < size) {
109          len = sizeof(int);          len = sizeof(int);
110          setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *)&size, len);          setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *)&size, len);
111      }      }
112      return TCL_OK;      return TCL_OK;
113  }  }
114    
115  /* End of tcliosock.c */  /* End of tcliosock.c */

Legend:
Removed from v.64  
changed lines
  Added in v.71

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25