OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tcl/] [generic/] [tclIOSock.c] - Diff between revs 578 and 1765

Only display areas with differences | Details | Blame | View Log

Rev 578 Rev 1765
/*
/*
 * tclIOSock.c --
 * tclIOSock.c --
 *
 *
 *      Common routines used by all socket based channel types.
 *      Common routines used by all socket based channel types.
 *
 *
 * Copyright (c) 1995 Sun Microsystems, Inc.
 * Copyright (c) 1995 Sun Microsystems, Inc.
 *
 *
 * See the file "license.terms" for information on usage and redistribution
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 *
 * RCS: @(#) $Id: tclIOSock.c,v 1.1.1.1 2002-01-16 10:25:27 markom Exp $
 * RCS: @(#) $Id: tclIOSock.c,v 1.1.1.1 2002-01-16 10:25:27 markom Exp $
 */
 */
 
 
#include "tclInt.h"
#include "tclInt.h"
#include "tclPort.h"
#include "tclPort.h"


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * TclSockGetPort --
 * TclSockGetPort --
 *
 *
 *      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.
 *      Used by socket creation code to get port numbers and resolve
 *      Used by socket creation code to get port numbers and resolve
 *      registered service names to port numbers.
 *      registered service names to port numbers.
 *
 *
 * Results:
 * Results:
 *      A standard Tcl result.  On success, the port number is
 *      A standard Tcl result.  On success, the port number is
 *      returned in portPtr. On failure, an error message is left in
 *      returned in portPtr. On failure, an error message is left in
 *      interp->result.
 *      interp->result.
 *
 *
 * Side effects:
 * Side effects:
 *      None.
 *      None.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
int
int
TclSockGetPort(interp, string, proto, portPtr)
TclSockGetPort(interp, string, proto, portPtr)
    Tcl_Interp *interp;
    Tcl_Interp *interp;
    char *string;               /* Integer or service name */
    char *string;               /* Integer or service name */
    char *proto;                /* "tcp" or "udp", typically */
    char *proto;                /* "tcp" or "udp", typically */
    int *portPtr;               /* Return port number */
    int *portPtr;               /* Return port number */
{
{
    struct servent *sp;         /* Protocol info for named services */
    struct servent *sp;         /* Protocol info for named services */
    if (Tcl_GetInt(interp, string, portPtr) != TCL_OK) {
    if (Tcl_GetInt(interp, string, portPtr) != TCL_OK) {
        sp = getservbyname(string, proto);
        sp = getservbyname(string, proto);
        if (sp != NULL) {
        if (sp != NULL) {
            *portPtr = ntohs((unsigned short) sp->s_port);
            *portPtr = ntohs((unsigned short) sp->s_port);
            Tcl_ResetResult(interp);    /* clear error message */
            Tcl_ResetResult(interp);    /* clear error message */
            return TCL_OK;
            return TCL_OK;
        }
        }
        return TCL_ERROR;
        return TCL_ERROR;
    }
    }
    if (Tcl_GetInt(interp, string, portPtr) != TCL_OK) {
    if (Tcl_GetInt(interp, string, portPtr) != TCL_OK) {
        return TCL_ERROR;
        return TCL_ERROR;
    }
    }
    if (*portPtr > 0xFFFF) {
    if (*portPtr > 0xFFFF) {
        Tcl_AppendResult(interp, "couldn't open socket: port number too high",
        Tcl_AppendResult(interp, "couldn't open socket: port number too high",
                (char *) NULL);
                (char *) NULL);
        return TCL_ERROR;
        return TCL_ERROR;
    }
    }
    return TCL_OK;
    return TCL_OK;
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * TclSockMinimumBuffers --
 * TclSockMinimumBuffers --
 *
 *
 *      Ensure minimum buffer sizes (non zero).
 *      Ensure minimum buffer sizes (non zero).
 *
 *
 * Results:
 * Results:
 *      A standard Tcl result.
 *      A standard Tcl result.
 *
 *
 * Side effects:
 * Side effects:
 *      Sets SO_SNDBUF and SO_RCVBUF sizes.
 *      Sets SO_SNDBUF and SO_RCVBUF sizes.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
int
int
TclSockMinimumBuffers(sock, size)
TclSockMinimumBuffers(sock, size)
    int sock;                   /* Socket file descriptor */
    int sock;                   /* Socket file descriptor */
    int size;                   /* Minimum buffer size */
    int size;                   /* Minimum buffer size */
{
{
    int current;
    int current;
    int len;
    int len;
 
 
    len = sizeof(int);
    len = sizeof(int);
    getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *)&current, &len);
    getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *)&current, &len);
    if (current < size) {
    if (current < size) {
        len = sizeof(int);
        len = sizeof(int);
        setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *)&size, len);
        setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *)&size, len);
    }
    }
    len = sizeof(int);
    len = sizeof(int);
    getsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *)&current, &len);
    getsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *)&current, &len);
    if (current < size) {
    if (current < size) {
        len = sizeof(int);
        len = sizeof(int);
        setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *)&size, len);
        setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *)&size, len);
    }
    }
    return TCL_OK;
    return TCL_OK;
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.