The R Project SVN R

Rev

Rev 59039 | Rev 68949 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 59039 Rev 59198
Line 1... Line 1...
1
/*
1
/*
2
 *  R : A Computer Language for Statistical Data Analysis
2
 *  R : A Computer Language for Statistical Data Analysis
3
 *  Copyright (C)  2001-5   The R Core Team.
3
 *  Copyright (C)  2001-12   The R Core Team.
4
 *
4
 *
5
 *  This program is free software; you can redistribute it and/or modify
5
 *  This program is free software; you can redistribute it and/or modify
6
 *  it under the terms of the GNU General Public License as published by
6
 *  it under the terms of the GNU General Public License as published by
7
 *  the Free Software Foundation; either version 2 of the License, or
7
 *  the Free Software Foundation; either version 2 of the License, or
8
 *  (at your option) any later version.
8
 *  (at your option) any later version.
Line 86... Line 86...
86
	sprintf(buf, "->%s:%d", con->description, this->port);
86
	sprintf(buf, "->%s:%d", con->description, this->port);
87
	strcpy(con->description, buf);
87
	strcpy(con->description, buf);
88
    }
88
    }
89
    this->fd = sock;
89
    this->fd = sock;
90
 
90
 
91
    mlen = strlen(con->mode);
91
    mlen = (int) strlen(con->mode);
92
    con->isopen = TRUE;
92
    con->isopen = TRUE;
93
    if(mlen >= 2 && con->mode[mlen - 1] == 'b') con->text = FALSE;
93
    if(mlen >= 2 && con->mode[mlen - 1] == 'b') con->text = FALSE;
94
    else con->text = TRUE;
94
    else con->text = TRUE;
95
    set_iconv(con); /* OK for output, at least */
95
    set_iconv(con); /* OK for output, at least */
96
    con->save = -1000;
96
    con->save = -1000;
Line 102... Line 102...
102
    Rsockconn this = (Rsockconn)con->private;
102
    Rsockconn this = (Rsockconn)con->private;
103
    R_SockClose(this->fd);
103
    R_SockClose(this->fd);
104
    con->isopen = FALSE;
104
    con->isopen = FALSE;
105
}
105
}
106
 
106
 
107
static int sock_read_helper(Rconnection con, void *ptr, size_t size)
107
static size_t sock_read_helper(Rconnection con, void *ptr, size_t size)
108
{
108
{
109
    Rsockconn this = (Rsockconn)con->private;
109
    Rsockconn this = (Rsockconn)con->private;
110
    int res;
110
    ssize_t res;
111
    int nread = 0, n;
111
    size_t nread = 0, n;
112
 
112
 
113
    con->incomplete = FALSE;
113
    con->incomplete = FALSE;
114
    do {
114
    do {
115
	/* read data into the buffer if it's empty and size > 0 */
115
	/* read data into the buffer if it's empty and size > 0 */
116
	if (size > 0 && this->pstart == this->pend) {
116
	if (size > 0 && this->pstart == this->pend) {
Line 146... Line 146...
146
 
146
 
147
 
147
 
148
static int sock_fgetc_internal(Rconnection con)
148
static int sock_fgetc_internal(Rconnection con)
149
{
149
{
150
    unsigned char c;
150
    unsigned char c;
151
    int n;
151
    size_t n;
152
 
152
 
153
    n = sock_read_helper(con, (char *)&c, 1);
153
    n = sock_read_helper(con, (char *)&c, 1);
154
    return (n == 1) ? c : R_EOF;
154
    return (n == 1) ? c : R_EOF;
155
}
155
}
156
 
156
 
Line 163... Line 163...
163
static size_t sock_write(const void *ptr, size_t size, size_t nitems,
163
static size_t sock_write(const void *ptr, size_t size, size_t nitems,
164
			 Rconnection con)
164
			 Rconnection con)
165
{
165
{
166
    Rsockconn this = (Rsockconn)con->private;
166
    Rsockconn this = (Rsockconn)con->private;
167
 
167
 
168
    return R_SockWrite(this->fd, ptr, size * nitems, this->timeout)/size;
168
    return R_SockWrite(this->fd, ptr, (int)(size * nitems), this->timeout)/size;
169
}
169
}
170
 
170
 
171
Rconnection in_R_newsock(const char *host, int port, int server,
171
Rconnection in_R_newsock(const char *host, int port, int server,
172
			 const char * const mode, int timeout)
172
			 const char * const mode, int timeout)
173
{
173
{