Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(790)

Unified Diff: third_party/grpc/src/php/ext/grpc/byte_buffer.c

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/grpc/src/php/ext/grpc/byte_buffer.h ('k') | third_party/grpc/src/php/ext/grpc/call.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/grpc/src/php/ext/grpc/byte_buffer.c
diff --git a/third_party/tcmalloc/chromium/src/base/thread_lister.c b/third_party/grpc/src/php/ext/grpc/byte_buffer.c
similarity index 55%
copy from third_party/tcmalloc/chromium/src/base/thread_lister.c
copy to third_party/grpc/src/php/ext/grpc/byte_buffer.c
index bc180dba7a9f2ba3b8261009c8af85f0b1d4a023..8be0a206073698d90a9890b27c977a74aaa937a2 100644
--- a/third_party/tcmalloc/chromium/src/base/thread_lister.c
+++ b/third_party/grpc/src/php/ext/grpc/byte_buffer.c
@@ -1,4 +1,6 @@
-/* Copyright (c) 2005-2007, Google Inc.
+/*
+ *
+ * Copyright 2015, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -27,51 +29,50 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * ---
- * Author: Markus Gutschke
*/
+#ifdef HAVE_CONFIG_H
#include "config.h"
-#include <stdio.h> /* needed for NULL on some powerpc platforms (?!) */
-#ifdef HAVE_SYS_PRCTL
-# include <sys/prctl.h>
#endif
-#include "base/thread_lister.h"
-#include "base/linuxthreads.h"
-/* Include other thread listers here that define THREADS macro
- * only when they can provide a good implementation.
- */
-#ifndef THREADS
+#include <php.h>
+#include <php_ini.h>
+#include <ext/standard/info.h>
+#include <ext/spl/spl_exceptions.h>
+#include "php_grpc.h"
-/* Default trivial thread lister for single-threaded applications,
- * or if the multi-threading code has not been ported, yet.
- */
+#include <string.h>
-int ListAllProcessThreads(void *parameter,
- ListAllProcessThreadsCallBack callback, ...) {
- int rc;
- va_list ap;
- pid_t pid;
+#include "byte_buffer.h"
-#ifdef HAVE_SYS_PRCTL
- int dumpable = prctl(PR_GET_DUMPABLE, 0);
- if (!dumpable)
- prctl(PR_SET_DUMPABLE, 1);
-#endif
- va_start(ap, callback);
- pid = getpid();
- rc = callback(parameter, 1, &pid, ap);
- va_end(ap);
-#ifdef HAVE_SYS_PRCTL
- if (!dumpable)
- prctl(PR_SET_DUMPABLE, 0);
-#endif
- return rc;
-}
+#include <grpc/grpc.h>
+#include <grpc/byte_buffer_reader.h>
+#include <grpc/support/slice.h>
-int ResumeAllProcessThreads(int num_threads, pid_t *thread_pids) {
- return 1;
+grpc_byte_buffer *string_to_byte_buffer(char *string, size_t length) {
+ gpr_slice slice = gpr_slice_from_copied_buffer(string, length);
+ grpc_byte_buffer *buffer = grpc_raw_byte_buffer_create(&slice, 1);
+ gpr_slice_unref(slice);
+ return buffer;
}
-#endif /* ifndef THREADS */
+void byte_buffer_to_string(grpc_byte_buffer *buffer, char **out_string,
+ size_t *out_length) {
+ if (buffer == NULL) {
+ *out_string = NULL;
+ *out_length = 0;
+ return;
+ }
+ size_t length = grpc_byte_buffer_length(buffer);
+ char *string = ecalloc(length + 1, sizeof(char));
+ size_t offset = 0;
+ grpc_byte_buffer_reader reader;
+ grpc_byte_buffer_reader_init(&reader, buffer);
+ gpr_slice next;
+ while (grpc_byte_buffer_reader_next(&reader, &next) != 0) {
+ memcpy(string + offset, GPR_SLICE_START_PTR(next), GPR_SLICE_LENGTH(next));
+ offset += GPR_SLICE_LENGTH(next);
+ }
+ *out_string = string;
+ *out_length = length;
+}
« no previous file with comments | « third_party/grpc/src/php/ext/grpc/byte_buffer.h ('k') | third_party/grpc/src/php/ext/grpc/call.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698