static PyObject * GenericStreamType_iternext(genericstreamobject *self) { if (self->blockiter == 1) return generic_readline(self, 0); return generic_read(self, self->blockiter); }
int pvfsread(pfile * fp,char * buffer,int buffer_size, int current_offset) { if(fp) { int read_size= 0 ; read_size = generic_read(fp,buffer,current_offset,buffer_size,&credentials); return read_size; } return -1; }
// API: open a fancy image struct fancy_image *fancy_image_open(char *filename, char *options) { // create return struct and its alias //struct fancy_image r[1]; struct fancy_image *r = xmalloc(sizeof*r); // I hate this malloc! struct FI *f = (void*)r; // process options parameter interpret_options(f, options); if (f->option_verbose) fprintf(stderr, "fancy_image_open\n\tf=" "\"%s\"\n\to=\"%s\"\n", filename, options); // if "c", do create the file if (f->option_creat) generic_create(f, filename); // read the image f->gdal = f->tiffo = false; generic_read(f, filename); if (f->option_verbose) { fprintf(stderr, "FANCY IMAGE \"%s\"\n", filename); fprintf(stderr, "\tw = %d\n", f->w); fprintf(stderr, "\th = %d\n", f->h); fprintf(stderr, "\tpd = %d\n", f->pd); fprintf(stderr, "\tno = %d\n", f->no); fprintf(stderr, "\n"); fprintf(stderr, "\tmax_octaves= %d\n", f->max_octaves); fprintf(stderr, "\ttiffo = %d\n", f->tiffo); fprintf(stderr, "\tmegabytes = %g\n", f->megabytes); } // return image struct return r; }
static struct ast_frame *slinear192_read(struct ast_filestream *s, int *whennext){return generic_read(s, whennext, 7680, AST_FORMAT_SLINEAR192);}
static struct ast_frame *slinear96_read(struct ast_filestream *s, int *whennext){return generic_read(s, whennext, 3840, AST_FORMAT_SLINEAR96);}
static struct ast_frame *slinear48_read(struct ast_filestream *s, int *whennext){return generic_read(s, whennext, 1920, AST_FORMAT_SLINEAR48);}
static struct ast_frame *slinear24_read(struct ast_filestream *s, int *whennext){return generic_read(s, whennext, 960, AST_FORMAT_SLINEAR24);}
static void read_select(struct socket *socket) { struct read_buffer *rb = socket->read_buffer; ssize_t rd; assertm(rb != NULL, "read socket has no buffer"); if_assert_failed { socket->ops->done(socket, connection_state(S_INTERNAL)); return; } /* We are making some progress, therefore reset the timeout; we do this * for read_select() to avoid that the periodic calls to user handlers * has to do it. */ socket->ops->set_timeout(socket, connection_state(0)); if (!socket->duplex) clear_handlers(socket->fd); if (!rb->freespace) { int size = RD_SIZE(rb, rb->length); rb = mem_realloc(rb, size); if (!rb) { socket->ops->done(socket, connection_state(S_OUT_OF_MEM)); return; } rb->freespace = size - sizeof(*rb) - rb->length; assert(rb->freespace > 0); socket->read_buffer = rb; } #ifdef CONFIG_SSL if (socket->ssl) { rd = ssl_read(socket, rb->data + rb->length, rb->freespace); } else #endif { rd = generic_read(socket, rb->data + rb->length, rb->freespace); } switch (rd) { #ifdef CONFIG_SSL case SOCKET_SSL_WANT_READ: read_from_socket(socket, rb, connection_state(S_TRANS), rb->done); break; #endif case SOCKET_CANT_READ: if (socket->state != SOCKET_RETRY_ONCLOSE) { socket->state = SOCKET_CLOSED; rb->done(socket, rb); break; } socket->ops->retry(socket, connection_state(S_CANT_READ)); break; case SOCKET_SYSCALL_ERROR: socket->ops->retry(socket, connection_state_for_errno(errno)); break; case SOCKET_INTERNAL_ERROR: /* The global errno variable is used for passing * internal connection_state error value. */ socket->ops->done(socket, connection_state(errno)); break; default: debug_transfer_log(rb->data + rb->length, rd); rb->length += rd; rb->freespace -= rd; assert(rb->freespace >= 0); rb->done(socket, rb); } }
static struct ast_frame *slinear192_read(struct ast_filestream *s, int *whennext){return generic_read(s, whennext, 7680);}
static struct ast_frame *slinear44_read(struct ast_filestream *s, int *whennext){return generic_read(s, whennext, 1764);}
/* read a line (return NULL on eof) */ static PyObject * generic_readline(genericstreamobject *self, Py_ssize_t size) { bufitem *linebuf, *item; PyObject *result; char *jptr; const char *newline; Py_ssize_t cursize, leftsize, readsize; if (size < 0) size = 0; /* read default chunks */ if (!(result = generic_read(self, size))) /* maybe just EOF */ return NULL; if (!(linebuf = bufitem_new())) { Py_DECREF(result); return NULL; } linebuf->next = NULL; linebuf->load = result; item = linebuf; readsize = 0; for (;;) { jptr = PyString_AS_STRING(item->load); cursize = PyString_GET_SIZE(item->load); if ((readsize + cursize) < readsize) { PyErr_SetString(PyExc_OverflowError, "Buffer became too big"); goto error; } readsize += cursize; leftsize = cursize - ((size > 0) && (size < readsize) ? readsize - size: 0); if ( (leftsize > 0) && (newline = memchr(jptr, '\n', (size_t)leftsize))) { /* split at newline */ size = readsize - cursize + ((Py_ssize_t)(newline - jptr) + 1); break; } else if ((size > 0) && (readsize >= size)) /* cut it here and now */ break; /* read next chunk, if any */ result = generic_read(self, size - ((size > 0) ? readsize: 0)); if (!result) { if (PyErr_Occurred()) goto error; /* else */ size = readsize; break; } if (!(item->next = bufitem_new())) { Py_DECREF(result); goto error; } item = item->next; item->next = NULL; item->load = result; } /* flatten the buffer chain */ if (size == 0) size = readsize; /* > 0 by definition */ if (!(result = PyString_FromStringAndSize(NULL, size))) goto error; jptr = PyString_AS_STRING(result); newline = jptr + (size_t)size; while (linebuf && (jptr < newline)) { cursize = PyString_GET_SIZE(linebuf->load); if ((jptr + cursize) > newline) { /* need to split */ if (!(item = bufitem_new())) { Py_DECREF(result); goto error; } item->next = linebuf->next; item->load = PyString_FromStringAndSize( PyString_AS_STRING(linebuf->load) + (size_t)(newline - jptr), (cursize - (Py_ssize_t)(newline - jptr)) ); if (!item->load) { (void)bufitem_del(item); Py_DECREF(result); goto error; } linebuf->next = item; cursize = (Py_ssize_t)(newline - jptr); } (void)memcpy(jptr, PyString_AS_STRING(linebuf->load), (size_t)cursize); jptr += cursize; linebuf = bufitem_del(linebuf); } /* push back unused data */ if (linebuf) { item = linebuf; readsize = PyString_GET_SIZE(item->load); while (item->next) { item = item->next; readsize += PyString_GET_SIZE(item->load); } if (self->rbuf_last) { item->next = self->rbuf_last; self->rbuf_last = linebuf; self->rbuf_size += readsize; /* just read from it, need no check */ } else { self->rbuf = item; self->rbuf_last = linebuf; self->rbuf_size = readsize; } } return result; error: item = linebuf; while ((item = bufitem_del(item))) ; return NULL; }