os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/generic/tclIOSock.c
First public contribution.
4 * Common routines used by all socket based channel types.
6 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
8 * See the file "license.terms" for information on usage and redistribution
9 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11 * RCS: @(#) $Id: tclIOSock.c,v 1.7 2002/07/29 16:54:41 rmax Exp $
18 *---------------------------------------------------------------------------
22 * Maps from a string, which could be a service name, to a port.
23 * Used by socket creation code to get port numbers and resolve
24 * registered service names to port numbers.
27 * A standard Tcl result. On success, the port number is returned
28 * in portPtr. On failure, an error message is left in the interp's
34 *---------------------------------------------------------------------------
38 TclSockGetPort(interp, string, proto, portPtr)
40 char *string; /* Integer or service name */
41 char *proto; /* "tcp" or "udp", typically */
42 int *portPtr; /* Return port number */
44 struct servent *sp; /* Protocol info for named services */
48 if (Tcl_GetInt(NULL, string, portPtr) != TCL_OK) {
50 * Don't bother translating 'proto' to native.
53 native = Tcl_UtfToExternalDString(NULL, string, -1, &ds);
54 sp = getservbyname(native, proto); /* INTL: Native. */
57 *portPtr = ntohs((unsigned short) sp->s_port);
61 if (Tcl_GetInt(interp, string, portPtr) != TCL_OK) {
64 if (*portPtr > 0xFFFF) {
65 Tcl_AppendResult(interp, "couldn't open socket: port number too high",
73 *----------------------------------------------------------------------
75 * TclSockMinimumBuffers --
77 * Ensure minimum buffer sizes (non zero).
80 * A standard Tcl result.
83 * Sets SO_SNDBUF and SO_RCVBUF sizes.
85 *----------------------------------------------------------------------
89 TclSockMinimumBuffers(sock, size)
90 int sock; /* Socket file descriptor */
91 int size; /* Minimum buffer size */
97 getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *)¤t, &len);
100 setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *)&size, len);
103 getsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *)¤t, &len);
104 if (current < size) {
106 setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *)&size, len);