/* {{{ MongoCursor->doQuery */ PHP_METHOD(MongoCursor, doQuery) { int sent; mongo_msg_header header; mongo_cursor *cursor; CREATE_BUF(buf, INITIAL_BUF_SIZE); cursor = (mongo_cursor*)zend_object_store_get_object(getThis() TSRMLS_CC); MONGO_CHECK_INITIALIZED(cursor->link, MongoCursor); CREATE_HEADER_WITH_OPTS(buf, cursor->ns, OP_QUERY, cursor->opts); serialize_int(&buf, cursor->skip); serialize_int(&buf, cursor->limit); zval_to_bson(&buf, HASH_P(cursor->query), NO_PREP TSRMLS_CC); if (cursor->fields && zend_hash_num_elements(HASH_P(cursor->fields)) > 0) { zval_to_bson(&buf, HASH_P(cursor->fields), NO_PREP TSRMLS_CC); } serialize_size(buf.start, &buf); // sends sent = mongo_say(cursor->link, &buf TSRMLS_CC); efree(buf.start); if (sent == FAILURE) { zend_throw_exception(mongo_ce_CursorException, "couldn't send query.", 0 TSRMLS_CC); return; } get_reply(cursor TSRMLS_CC); }
static void storage_serialize(at **pp, int code) { storage_t *st; int type, kind; size_t size; if (code != SRZ_READ) { st = Mptr(*pp); type = (int)st->type; kind = (int)st->kind; size = st->size; } // Read/write basic info serialize_int(&type, code); serialize_int(&kind, code); serialize_size(&size, code); // Create storage if needed if (code == SRZ_READ) { st = new_storage_managed((storage_type_t)type, size, NIL); *pp = st->backptr; } // Read/write storage data st = Mptr(*pp); if (type == ST_AT) { at **data = st->data; for (int i=0; i<size; i++) serialize_atstar( &data[i], code); } else { FILE *f = serialization_file_descriptor(code); if (code == SRZ_WRITE) { extern int in_bwrite; in_bwrite += sizeof(int) + size * storage_sizeof[type]; write4(f, STORAGE_NORMAL); storage_save(st, f); } else if (code == SRZ_READ) { int magic = read4(f); storage_load(st, f); if (magic == STORAGE_SWAPPED) swap_buffer(st->data, size, storage_sizeof[type]); else if (magic != STORAGE_NORMAL) RAISEF("Corrupted binary file",NIL); } } }
/* {{{ MongoCursor::hasNext */ PHP_METHOD(MongoCursor, hasNext) { mongo_msg_header header; buffer buf; int size; mongo_cursor *cursor = (mongo_cursor*)zend_object_store_get_object(getThis() TSRMLS_CC); MONGO_CHECK_INITIALIZED(cursor->link, MongoCursor); if (!cursor->started_iterating) { MONGO_METHOD(MongoCursor, doQuery)(INTERNAL_FUNCTION_PARAM_PASSTHRU); cursor->started_iterating = 1; } if ((cursor->limit > 0 && cursor->at >= cursor->limit) || cursor->num == 0) { RETURN_FALSE; } if (cursor->at < cursor->num) { RETURN_TRUE; } else if (cursor->cursor_id == 0) { RETURN_FALSE; } // we have to go and check with the db size = 34+strlen(cursor->ns); buf.start = (unsigned char*)emalloc(size); buf.pos = buf.start; buf.end = buf.start + size; CREATE_RESPONSE_HEADER(buf, cursor->ns, strlen(cursor->ns), cursor->header.request_id, OP_GET_MORE); serialize_int(&buf, cursor->limit); serialize_long(&buf, cursor->cursor_id); serialize_size(buf.start, &buf); // fails if we're out of elems if(mongo_say(cursor->link, &buf TSRMLS_CC) == FAILURE) { efree(buf.start); RETURN_FALSE; } efree(buf.start); // if we have cursor->at == cursor->num && recv fails, // we're probably just out of results RETURN_BOOL(get_reply(cursor TSRMLS_CC) == SUCCESS); }
void clipboard_copy_size(const Size& size){ Clipboard clip; if (clip.Good()){ clip.SetText(serialize_size(size)); } }