commit
62d424a1a4
60 changed files with 1843 additions and 175 deletions
@ -0,0 +1,60 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2014, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef __GRPC_SUPPORT_ENV_H__ |
||||
#define __GRPC_SUPPORT_ENV_H__ |
||||
|
||||
#include <stdio.h> |
||||
|
||||
#include <grpc/support/slice.h> |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
/* Env utility functions */ |
||||
|
||||
/* Gets the environment variable value with the specified name.
|
||||
Returns a newly allocated string. It is the responsability of the caller to |
||||
gpr_free the return value if not NULL (which means that the environment |
||||
variable exists). */ |
||||
char *gpr_getenv(const char *name); |
||||
|
||||
/* Sets the the environment with the specified name to the specified value. */ |
||||
void gpr_setenv(const char *name, const char *value); |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* __GRPC_SUPPORT_ENV_H__ */ |
@ -0,0 +1,61 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2014, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
/* for secure_getenv. */ |
||||
#ifndef _GNU_SOURCE |
||||
#define _GNU_SOURCE |
||||
#endif |
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#ifdef GPR_LINUX_ENV |
||||
|
||||
#include "src/core/support/env.h" |
||||
|
||||
#include <stdlib.h> |
||||
|
||||
#include <grpc/support/log.h> |
||||
|
||||
#include "src/core/support/string.h" |
||||
|
||||
char *gpr_getenv(const char *name) { |
||||
char *result = secure_getenv(name); |
||||
return result == NULL ? result : gpr_strdup(result); |
||||
} |
||||
|
||||
void gpr_setenv(const char *name, const char *value) { |
||||
int res = setenv(name, value, 1); |
||||
GPR_ASSERT(res == 0); |
||||
} |
||||
|
||||
#endif /* GPR_LINUX_ENV */ |
@ -0,0 +1,56 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2014, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#ifdef GPR_POSIX_ENV |
||||
|
||||
#include "src/core/support/env.h" |
||||
|
||||
#include <stdlib.h> |
||||
|
||||
#include <grpc/support/log.h> |
||||
|
||||
#include "src/core/support/string.h" |
||||
|
||||
char *gpr_getenv(const char *name) { |
||||
char *result = getenv(name); |
||||
return result == NULL ? result : gpr_strdup(result); |
||||
} |
||||
|
||||
void gpr_setenv(const char *name, const char *value) { |
||||
int res = setenv(name, value, 1); |
||||
GPR_ASSERT(res == 0); |
||||
} |
||||
|
||||
#endif /* GPR_POSIX_ENV */ |
@ -0,0 +1,61 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2014, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#ifdef GPR_WIN32 |
||||
|
||||
#include "src/core/support/env.h" |
||||
|
||||
#include <stdlib.h> |
||||
|
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/log.h> |
||||
|
||||
char *gpr_getenv(const char *name) { |
||||
size_t required_size; |
||||
char *result = NULL; |
||||
|
||||
getenv_s(&required_size, NULL, 0, name); |
||||
if (required_size == 0) return NULL; |
||||
result = gpr_malloc(required_size); |
||||
getenv_s(&required_size, result, required_size, name); |
||||
return result; |
||||
} |
||||
|
||||
void gpr_setenv(const char *name, const char *value) { |
||||
errno_t res = _putenv_s(name, value); |
||||
GPR_ASSERT(res == 0); |
||||
} |
||||
|
||||
#endif /* GPR_WIN32 */ |
@ -0,0 +1,89 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2014, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#include "src/core/support/file.h" |
||||
|
||||
#include <errno.h> |
||||
#include <string.h> |
||||
|
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/log.h> |
||||
|
||||
#include "src/core/support/string.h" |
||||
|
||||
gpr_slice gpr_load_file(const char *filename, int *success) { |
||||
unsigned char *contents = NULL; |
||||
size_t contents_size = 0; |
||||
unsigned char buf[4096]; |
||||
char *error_msg = NULL; |
||||
gpr_slice result = gpr_empty_slice(); |
||||
FILE *file = fopen(filename, "rb"); |
||||
|
||||
if (file == NULL) { |
||||
gpr_asprintf(&error_msg, "Could not open file %s (error = %s).", filename, |
||||
strerror(errno)); |
||||
GPR_ASSERT(error_msg != NULL); |
||||
goto end; |
||||
} |
||||
|
||||
while (1) { |
||||
size_t bytes_read = fread(buf, 1, sizeof(buf), file); |
||||
if (bytes_read > 0) { |
||||
contents = gpr_realloc(contents, contents_size + bytes_read); |
||||
memcpy(contents + contents_size, buf, bytes_read); |
||||
contents_size += bytes_read; |
||||
} |
||||
if (bytes_read < sizeof(buf)) { |
||||
if (ferror(file)) { |
||||
gpr_asprintf(&error_msg, "Error %s occured while reading file %s.", |
||||
strerror(errno), filename); |
||||
GPR_ASSERT(error_msg != NULL); |
||||
goto end; |
||||
} else { |
||||
GPR_ASSERT(feof(file)); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
if (success != NULL) *success = 1; |
||||
result = gpr_slice_new(contents, contents_size, gpr_free); |
||||
|
||||
end: |
||||
if (error_msg != NULL) { |
||||
gpr_log(GPR_ERROR, "%s", error_msg); |
||||
gpr_free(error_msg); |
||||
if (success != NULL) *success = 0; |
||||
} |
||||
if (file != NULL) fclose(file); |
||||
return result; |
||||
} |
@ -0,0 +1,61 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2014, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef __GRPC_SUPPORT_FILE_H__ |
||||
#define __GRPC_SUPPORT_FILE_H__ |
||||
|
||||
#include <stdio.h> |
||||
|
||||
#include <grpc/support/slice.h> |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
/* File utility functions */ |
||||
|
||||
/* Loads the content of a file into a slice. The success parameter, if not NULL,
|
||||
will be set to 1 in case of success and 0 in case of failure. */ |
||||
gpr_slice gpr_load_file(const char *filename, int *success); |
||||
|
||||
/* Creates a temporary file from a prefix.
|
||||
If tmp_filename is not NULL, *tmp_filename is assigned the name of the |
||||
created file and it is the responsibility of the caller to gpr_free it |
||||
unless an error occurs in which case it will be set to NULL. */ |
||||
FILE *gpr_tmpfile(const char *prefix, char **tmp_filename); |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* __GRPC_SUPPORT_FILE_H__ */ |
@ -0,0 +1,97 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2014, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
/* Posix code for gpr fdopen and mkstemp support. */ |
||||
|
||||
#if !defined _POSIX_C_SOURCE || _POSIX_C_SOURCE < 200112L |
||||
#undef _POSIX_C_SOURCE |
||||
#define _POSIX_C_SOURCE 200112L |
||||
#endif |
||||
|
||||
/* Don't know why I have to do this for mkstemp, looks like _POSIX_C_SOURCE
|
||||
should be enough... */ |
||||
#ifndef _BSD_SOURCE |
||||
#define _BSD_SOURCE |
||||
#endif |
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#ifdef GPR_POSIX_FILE |
||||
|
||||
#include "src/core/support/file.h" |
||||
|
||||
#include <errno.h> |
||||
#include <stdlib.h> |
||||
#include <string.h> |
||||
#include <unistd.h> |
||||
|
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/log.h> |
||||
|
||||
#include "src/core/support/string.h" |
||||
|
||||
FILE *gpr_tmpfile(const char *prefix, char **tmp_filename) { |
||||
FILE *result = NULL; |
||||
char *template; |
||||
int fd; |
||||
|
||||
if (tmp_filename != NULL) *tmp_filename = NULL; |
||||
|
||||
gpr_asprintf(&template, "/tmp/%s_XXXXXX", prefix); |
||||
GPR_ASSERT(template != NULL); |
||||
|
||||
fd = mkstemp(template); |
||||
if (fd == -1) { |
||||
gpr_log(GPR_ERROR, "mkstemp failed for template %s with error %s.", |
||||
template, strerror(errno)); |
||||
goto end; |
||||
} |
||||
result = fdopen(fd, "w+"); |
||||
if (result == NULL) { |
||||
gpr_log(GPR_ERROR, "Could not open file %s from fd %d (error = %s).", |
||||
template, fd, strerror(errno)); |
||||
unlink(template); |
||||
close(fd); |
||||
goto end; |
||||
} |
||||
|
||||
end: |
||||
if (result != NULL && tmp_filename != NULL) { |
||||
*tmp_filename = template; |
||||
} else { |
||||
gpr_free(template); |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
#endif /* GPR_POSIX_FILE */ |
@ -0,0 +1,83 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2014, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#ifdef GPR_WIN32 |
||||
|
||||
#include <io.h> |
||||
#include <stdio.h> |
||||
#include <string.h> |
||||
#include <tchar.h> |
||||
|
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/log.h> |
||||
|
||||
#include "src/core/support/file.h" |
||||
#include "src/core/support/string_win32.h" |
||||
|
||||
FILE *gpr_tmpfile(const char *prefix, char **tmp_filename_out) { |
||||
FILE *result = NULL; |
||||
LPTSTR template_string = NULL; |
||||
TCHAR tmp_path[MAX_PATH]; |
||||
TCHAR tmp_filename[MAX_PATH]; |
||||
DWORD status; |
||||
UINT success; |
||||
|
||||
if (tmp_filename_out != NULL) *tmp_filename_out = NULL; |
||||
|
||||
/* Convert our prefix to TCHAR. */ |
||||
template_string = gpr_char_to_tchar(prefix); |
||||
GPR_ASSERT(template_string); |
||||
|
||||
/* Get the path to the best temporary folder available. */ |
||||
status = GetTempPath(MAX_PATH, tmp_path); |
||||
if (status == 0 || status > MAX_PATH) goto end; |
||||
|
||||
/* Generate a unique filename with our template + temporary path. */ |
||||
success = GetTempFileName(tmp_path, template_string, 0, tmp_filename); |
||||
if (!success) goto end; |
||||
|
||||
/* Open a file there. */ |
||||
if (_tfopen_s(&result, tmp_filename, TEXT("wb+")) != 0) goto end; |
||||
|
||||
end: |
||||
if (result && tmp_filename) { |
||||
*tmp_filename_out = gpr_tchar_to_char(tmp_filename); |
||||
} |
||||
|
||||
gpr_free(tmp_filename); |
||||
return result; |
||||
} |
||||
|
||||
#endif /* GPR_WIN32 */ |
@ -0,0 +1,49 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2014, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef __GRPC_SUPPORT_STRING_WIN32_H__ |
||||
#define __GRPC_SUPPORT_STRING_WIN32_H__ |
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#ifdef GPR_WIN32 |
||||
|
||||
#include <windows.h> |
||||
|
||||
/* These allocate new strings using gpr_malloc to convert from and to utf-8. */ |
||||
LPTSTR gpr_char_to_tchar(LPCSTR input); |
||||
LPSTR gpr_tchar_to_char(LPCTSTR input); |
||||
|
||||
#endif /* GPR_WIN32 */ |
||||
|
||||
#endif /* __GRPC_SUPPORT_STRING_WIN32_H__ */ |
@ -0,0 +1,31 @@ |
||||
using System; |
||||
|
||||
namespace Google.GRPC.Core |
||||
{ |
||||
/// <summary> |
||||
/// For serializing and deserializing messages. |
||||
/// </summary> |
||||
public interface IMarshaller<T> |
||||
{ |
||||
byte[] Serialize(T value); |
||||
|
||||
T Deserialize(byte[] payload); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// UTF-8 Marshalling for string. Useful for testing. |
||||
/// </summary> |
||||
internal class StringMarshaller : IMarshaller<string> { |
||||
|
||||
public byte[] Serialize(string value) |
||||
{ |
||||
return System.Text.Encoding.UTF8.GetBytes(value); |
||||
} |
||||
|
||||
public string Deserialize(byte[] payload) |
||||
{ |
||||
return System.Text.Encoding.UTF8.GetString(payload); |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,38 @@ |
||||
using System; |
||||
using Google.GRPC.Core.Internal; |
||||
|
||||
namespace Google.GRPC.Core.Internal |
||||
{ |
||||
/// <summary> |
||||
/// Observer that writes all arriving messages to a call abstraction (in blocking fashion) |
||||
/// and then halfcloses the call. Used for server-side call handling. |
||||
/// </summary> |
||||
internal class ServerWritingObserver<TWrite, TRead> : IObserver<TWrite> |
||||
{ |
||||
readonly AsyncCall<TWrite, TRead> call; |
||||
|
||||
public ServerWritingObserver(AsyncCall<TWrite, TRead> call) |
||||
{ |
||||
this.call = call; |
||||
} |
||||
|
||||
public void OnCompleted() |
||||
{ |
||||
// TODO: how bad is the Wait here? |
||||
call.WriteStatusAsync(new Status(StatusCode.GRPC_STATUS_OK, "")).Wait(); |
||||
} |
||||
|
||||
public void OnError(Exception error) |
||||
{ |
||||
// TODO: handle this... |
||||
throw new InvalidOperationException("This should never be called."); |
||||
} |
||||
|
||||
public void OnNext(TWrite value) |
||||
{ |
||||
// TODO: how bad is the Wait here? |
||||
call.WriteAsync(value).Wait(); |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,64 @@ |
||||
using System; |
||||
|
||||
namespace Google.GRPC.Core |
||||
{ |
||||
public enum MethodType |
||||
{ |
||||
Unary, |
||||
ClientStreaming, |
||||
ServerStreaming, |
||||
DuplexStreaming |
||||
} |
||||
|
||||
/// <summary> |
||||
/// A description of a service method. |
||||
/// </summary> |
||||
public class Method<TRequest, TResponse> |
||||
{ |
||||
readonly MethodType type; |
||||
readonly string name; |
||||
readonly IMarshaller<TRequest> requestMarshaller; |
||||
readonly IMarshaller<TResponse> responseMarshaller; |
||||
|
||||
public Method(MethodType type, string name, IMarshaller<TRequest> requestMarshaller, IMarshaller<TResponse> responseMarshaller) |
||||
{ |
||||
this.type = type; |
||||
this.name = name; |
||||
this.requestMarshaller = requestMarshaller; |
||||
this.responseMarshaller = responseMarshaller; |
||||
} |
||||
|
||||
public MethodType Type |
||||
{ |
||||
get |
||||
{ |
||||
return this.type; |
||||
} |
||||
} |
||||
|
||||
public string Name |
||||
{ |
||||
get |
||||
{ |
||||
return this.name; |
||||
} |
||||
} |
||||
|
||||
public IMarshaller<TRequest> RequestMarshaller |
||||
{ |
||||
get |
||||
{ |
||||
return this.requestMarshaller; |
||||
} |
||||
} |
||||
|
||||
public IMarshaller<TResponse> ResponseMarshaller |
||||
{ |
||||
get |
||||
{ |
||||
return this.responseMarshaller; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,93 @@ |
||||
using System; |
||||
using Google.GRPC.Core.Internal; |
||||
|
||||
namespace Google.GRPC.Core |
||||
{ |
||||
internal interface IServerCallHandler |
||||
{ |
||||
void StartCall(string methodName, CallSafeHandle call, CompletionQueueSafeHandle cq); |
||||
} |
||||
|
||||
internal class UnaryRequestServerCallHandler<TRequest, TResponse> : IServerCallHandler |
||||
{ |
||||
readonly Method<TRequest, TResponse> method; |
||||
readonly UnaryRequestServerMethod<TRequest, TResponse> handler; |
||||
|
||||
public UnaryRequestServerCallHandler(Method<TRequest, TResponse> method, UnaryRequestServerMethod<TRequest, TResponse> handler) |
||||
{ |
||||
this.method = method; |
||||
this.handler = handler; |
||||
} |
||||
|
||||
public void StartCall(string methodName, CallSafeHandle call, CompletionQueueSafeHandle cq) |
||||
{ |
||||
var asyncCall = new AsyncCall<TResponse, TRequest>( |
||||
(msg) => method.ResponseMarshaller.Serialize(msg), |
||||
(payload) => method.RequestMarshaller.Deserialize(payload)); |
||||
|
||||
asyncCall.InitializeServer(call); |
||||
asyncCall.Accept(cq); |
||||
|
||||
var request = asyncCall.ReadAsync().Result; |
||||
|
||||
var responseObserver = new ServerWritingObserver<TResponse, TRequest>(asyncCall); |
||||
handler(request, responseObserver); |
||||
|
||||
asyncCall.Halfclosed.Wait(); |
||||
// TODO: wait until writing is finished |
||||
|
||||
asyncCall.WriteStatusAsync(new Status(StatusCode.GRPC_STATUS_OK, "")).Wait(); |
||||
asyncCall.Finished.Wait(); |
||||
} |
||||
} |
||||
|
||||
internal class StreamingRequestServerCallHandler<TRequest, TResponse> : IServerCallHandler |
||||
{ |
||||
readonly Method<TRequest, TResponse> method; |
||||
readonly StreamingRequestServerMethod<TRequest, TResponse> handler; |
||||
|
||||
public StreamingRequestServerCallHandler(Method<TRequest, TResponse> method, StreamingRequestServerMethod<TRequest, TResponse> handler) |
||||
{ |
||||
this.method = method; |
||||
this.handler = handler; |
||||
} |
||||
|
||||
public void StartCall(string methodName, CallSafeHandle call, CompletionQueueSafeHandle cq) |
||||
{ |
||||
var asyncCall = new AsyncCall<TResponse, TRequest>( |
||||
(msg) => method.ResponseMarshaller.Serialize(msg), |
||||
(payload) => method.RequestMarshaller.Deserialize(payload)); |
||||
|
||||
asyncCall.InitializeServer(call); |
||||
asyncCall.Accept(cq); |
||||
|
||||
var responseObserver = new ServerWritingObserver<TResponse, TRequest>(asyncCall); |
||||
var requestObserver = handler(responseObserver); |
||||
|
||||
// feed the requests |
||||
asyncCall.StartReadingToStream(requestObserver); |
||||
|
||||
asyncCall.Halfclosed.Wait(); |
||||
|
||||
asyncCall.WriteStatusAsync(new Status(StatusCode.GRPC_STATUS_OK, "")).Wait(); |
||||
asyncCall.Finished.Wait(); |
||||
} |
||||
} |
||||
|
||||
internal class NoSuchMethodCallHandler : IServerCallHandler |
||||
{ |
||||
public void StartCall(string methodName, CallSafeHandle call, CompletionQueueSafeHandle cq) |
||||
{ |
||||
// We don't care about the payload type here. |
||||
AsyncCall<byte[], byte[]> asyncCall = new AsyncCall<byte[], byte[]>( |
||||
(payload) => payload, (payload) => payload); |
||||
|
||||
asyncCall.InitializeServer(call); |
||||
asyncCall.Accept(cq); |
||||
asyncCall.WriteStatusAsync(new Status(StatusCode.GRPC_STATUS_UNIMPLEMENTED, "No such method.")).Wait(); |
||||
|
||||
asyncCall.Finished.Wait(); |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,25 @@ |
||||
using System; |
||||
|
||||
namespace Google.GRPC.Core |
||||
{ |
||||
// TODO: perhaps add also serverSideStreaming and clientSideStreaming |
||||
|
||||
public delegate void UnaryRequestServerMethod<TRequest, TResponse> (TRequest request, IObserver<TResponse> responseObserver); |
||||
|
||||
public delegate IObserver<TRequest> StreamingRequestServerMethod<TRequest, TResponse> (IObserver<TResponse> responseObserver); |
||||
|
||||
internal static class ServerCalls { |
||||
|
||||
public static IServerCallHandler UnaryRequestCall<TRequest, TResponse>(Method<TRequest, TResponse> method, UnaryRequestServerMethod<TRequest, TResponse> handler) |
||||
{ |
||||
return new UnaryRequestServerCallHandler<TRequest, TResponse>(method, handler); |
||||
} |
||||
|
||||
public static IServerCallHandler StreamingRequestCall<TRequest, TResponse>(Method<TRequest, TResponse> method, StreamingRequestServerMethod<TRequest, TResponse> handler) |
||||
{ |
||||
return new StreamingRequestServerCallHandler<TRequest, TResponse>(method, handler); |
||||
} |
||||
|
||||
} |
||||
} |
||||
|
@ -0,0 +1,64 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2014, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#include <stdio.h> |
||||
#include <string.h> |
||||
|
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/log.h> |
||||
|
||||
#include "src/core/support/env.h" |
||||
#include "src/core/support/string.h" |
||||
#include "test/core/util/test_config.h" |
||||
|
||||
#define LOG_TEST_NAME() gpr_log(GPR_INFO, "%s", __FUNCTION__) |
||||
|
||||
static void test_setenv_getenv(void) { |
||||
const char *name = "FOO"; |
||||
const char *value = "BAR"; |
||||
char *retrieved_value; |
||||
|
||||
LOG_TEST_NAME(); |
||||
|
||||
gpr_setenv(name, value); |
||||
retrieved_value = gpr_getenv(name); |
||||
GPR_ASSERT(retrieved_value != NULL); |
||||
GPR_ASSERT(!strcmp(value, retrieved_value)); |
||||
gpr_free(retrieved_value); |
||||
} |
||||
|
||||
int main(int argc, char **argv) { |
||||
grpc_test_init(argc, argv); |
||||
test_setenv_getenv(); |
||||
return 0; |
||||
} |
@ -0,0 +1,159 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2014, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#include <stdio.h> |
||||
#include <string.h> |
||||
|
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/log.h> |
||||
#include <grpc/support/slice.h> |
||||
|
||||
#include "src/core/support/file.h" |
||||
#include "src/core/support/string.h" |
||||
#include "test/core/util/test_config.h" |
||||
|
||||
#define LOG_TEST_NAME() gpr_log(GPR_INFO, "%s", __FUNCTION__) |
||||
|
||||
static const char prefix[] = "file_test"; |
||||
|
||||
static void test_load_empty_file(void) { |
||||
FILE *tmp = NULL; |
||||
gpr_slice slice; |
||||
int success; |
||||
char *tmp_name; |
||||
|
||||
LOG_TEST_NAME(); |
||||
|
||||
tmp = gpr_tmpfile(prefix, &tmp_name); |
||||
GPR_ASSERT(tmp_name != NULL); |
||||
GPR_ASSERT(tmp != NULL); |
||||
fclose(tmp); |
||||
|
||||
slice = gpr_load_file(tmp_name, &success); |
||||
GPR_ASSERT(success == 1); |
||||
GPR_ASSERT(GPR_SLICE_LENGTH(slice) == 0); |
||||
|
||||
remove(tmp_name); |
||||
gpr_free(tmp_name); |
||||
gpr_slice_unref(slice); |
||||
} |
||||
|
||||
static void test_load_failure(void) { |
||||
FILE *tmp = NULL; |
||||
gpr_slice slice; |
||||
int success; |
||||
char *tmp_name; |
||||
|
||||
LOG_TEST_NAME(); |
||||
|
||||
tmp = gpr_tmpfile(prefix, &tmp_name); |
||||
GPR_ASSERT(tmp_name != NULL); |
||||
GPR_ASSERT(tmp != NULL); |
||||
fclose(tmp); |
||||
remove(tmp_name); |
||||
|
||||
slice = gpr_load_file(tmp_name, &success); |
||||
GPR_ASSERT(success == 0); |
||||
GPR_ASSERT(GPR_SLICE_LENGTH(slice) == 0); |
||||
gpr_free(tmp_name); |
||||
gpr_slice_unref(slice); |
||||
} |
||||
|
||||
static void test_load_small_file(void) { |
||||
FILE *tmp = NULL; |
||||
gpr_slice slice; |
||||
int success; |
||||
char *tmp_name; |
||||
const char *blah = "blah"; |
||||
|
||||
LOG_TEST_NAME(); |
||||
|
||||
tmp = gpr_tmpfile(prefix, &tmp_name); |
||||
GPR_ASSERT(tmp_name != NULL); |
||||
GPR_ASSERT(tmp != NULL); |
||||
GPR_ASSERT(fwrite(blah, 1, strlen(blah), tmp) == strlen(blah)); |
||||
fclose(tmp); |
||||
|
||||
slice = gpr_load_file(tmp_name, &success); |
||||
GPR_ASSERT(success == 1); |
||||
GPR_ASSERT(GPR_SLICE_LENGTH(slice) == strlen(blah)); |
||||
GPR_ASSERT(!memcmp(GPR_SLICE_START_PTR(slice), blah, strlen(blah))); |
||||
|
||||
remove(tmp_name); |
||||
gpr_free(tmp_name); |
||||
gpr_slice_unref(slice); |
||||
} |
||||
|
||||
static void test_load_big_file(void) { |
||||
FILE *tmp = NULL; |
||||
gpr_slice slice; |
||||
int success; |
||||
char *tmp_name; |
||||
unsigned char buffer[124631]; |
||||
unsigned char *current; |
||||
size_t i; |
||||
|
||||
LOG_TEST_NAME(); |
||||
|
||||
for (i = 0; i < sizeof(buffer); i++) { |
||||
buffer[i] = 42; |
||||
} |
||||
|
||||
tmp = gpr_tmpfile(prefix, &tmp_name); |
||||
GPR_ASSERT(tmp != NULL); |
||||
GPR_ASSERT(tmp_name != NULL); |
||||
GPR_ASSERT(fwrite(buffer, 1, sizeof(buffer), tmp) == sizeof(buffer)); |
||||
fclose(tmp); |
||||
|
||||
slice = gpr_load_file(tmp_name, &success); |
||||
GPR_ASSERT(success == 1); |
||||
GPR_ASSERT(GPR_SLICE_LENGTH(slice) == sizeof(buffer)); |
||||
current = GPR_SLICE_START_PTR(slice); |
||||
for (i = 0; i < sizeof(buffer); i++) { |
||||
GPR_ASSERT(current[i] == 42); |
||||
} |
||||
|
||||
remove(tmp_name); |
||||
gpr_free(tmp_name); |
||||
gpr_slice_unref(slice); |
||||
} |
||||
|
||||
|
||||
int main(int argc, char **argv) { |
||||
grpc_test_init(argc, argv); |
||||
test_load_empty_file(); |
||||
test_load_failure(); |
||||
test_load_small_file(); |
||||
test_load_big_file(); |
||||
return 0; |
||||
} |
@ -0,0 +1,29 @@ |
||||
#!/bin/bash |
||||
|
||||
main() { |
||||
# restart builder vm and wait for images to sync to it |
||||
source grpc_docker.sh |
||||
./new_grpc_docker_builder.sh -igrpc-docker-builder-alt-2 -anone |
||||
cd ../../ |
||||
sleep 3600 |
||||
|
||||
# build images for all languages |
||||
languages=(cxx java go ruby node) |
||||
for lan in "${languages[@]}" |
||||
do |
||||
grpc_update_image $lan |
||||
done |
||||
|
||||
# restart client and server vm and wait for images to sync to them |
||||
cd tools/gce_setup |
||||
./new_grpc_docker_builder.sh -igrpc-docker-testclients -anone |
||||
./new_grpc_docker_builder.sh -igrpc-docker-server -anone |
||||
sleep 3600 |
||||
|
||||
# launch images for all languages on server |
||||
grpc_launch_servers grpc-docker-server |
||||
|
||||
} |
||||
|
||||
set -x |
||||
main "$@" |
@ -0,0 +1,12 @@ |
||||
]); |
||||
|
||||
var table = new google.visualization.Table(document.getElementById('table_div')); |
||||
|
||||
table.draw(data, {showRowNumber: true}); |
||||
} |
||||
</script> |
||||
</head> |
||||
<body> |
||||
<div id="table_div"></div> |
||||
</body> |
||||
</html> |
@ -0,0 +1,14 @@ |
||||
<html> |
||||
<head> |
||||
<script type="text/javascript" src="https://www.google.com/jsapi"></script> |
||||
<script type="text/javascript"> |
||||
google.load("visualization", "1", {packages:["table"]}); |
||||
google.setOnLoadCallback(drawTable); |
||||
|
||||
function drawTable() { |
||||
var data = new google.visualization.DataTable(); |
||||
data.addColumn('string', 'TestCase'); |
||||
data.addColumn('string', 'Client'); |
||||
data.addColumn('string', 'Server'); |
||||
data.addColumn('boolean', 'Pass'); |
||||
data.addRows([ |
Loading…
Reference in new issue