for bug #229, revert changes of allspace, for srs-librtmp branch build failed. 2.0.34
正在显示
9 个修改的文件
包含
402 行增加
和
512 行删除
| @@ -299,9 +299,8 @@ END | @@ -299,9 +299,8 @@ END | ||
| 299 | GDBDebug=" -g -O0" | 299 | GDBDebug=" -g -O0" |
| 300 | # the warning level. | 300 | # the warning level. |
| 301 | WarnLevel=" -Wall" | 301 | WarnLevel=" -Wall" |
| 302 | -# the compile in c++ standard. | ||
| 303 | -# @remark, donot specifies it for mingw. | ||
| 304 | -CppStd="-ansi" && echo $MSYSTEM|grep "MINGW">/dev/null && CppStd="" | 302 | +# the compile standard. |
| 303 | +CppStd="-ansi" | ||
| 305 | # for library compile | 304 | # for library compile |
| 306 | LibraryCompile=" -fPIC" | 305 | LibraryCompile=" -fPIC" |
| 307 | # performance of gprof | 306 | # performance of gprof |
| @@ -356,7 +355,7 @@ if [ $SRS_MIPS_UBUNTU12 = YES ]; then SrsLinkOptions="${SrsLinkOptions} -lgcc_eh | @@ -356,7 +355,7 @@ if [ $SRS_MIPS_UBUNTU12 = YES ]; then SrsLinkOptions="${SrsLinkOptions} -lgcc_eh | ||
| 356 | MODULE_ID="CORE" | 355 | MODULE_ID="CORE" |
| 357 | MODULE_DEPENDS=() | 356 | MODULE_DEPENDS=() |
| 358 | ModuleLibIncs=(${SRS_OBJS_DIR}) | 357 | ModuleLibIncs=(${SRS_OBJS_DIR}) |
| 359 | -MODULE_FILES=("srs_core" "srs_core_autofree" "srs_platform") | 358 | +MODULE_FILES=("srs_core" "srs_core_autofree") |
| 360 | CORE_INCS="src/core"; MODULE_DIR=${CORE_INCS} . auto/modules.sh | 359 | CORE_INCS="src/core"; MODULE_DIR=${CORE_INCS} . auto/modules.sh |
| 361 | CORE_OBJS="${MODULE_OBJS[@]}" | 360 | CORE_OBJS="${MODULE_OBJS[@]}" |
| 362 | # | 361 | # |
| @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 31 | // current release version | 31 | // current release version |
| 32 | #define VERSION_MAJOR 2 | 32 | #define VERSION_MAJOR 2 |
| 33 | #define VERSION_MINOR 0 | 33 | #define VERSION_MINOR 0 |
| 34 | -#define VERSION_REVISION 33 | 34 | +#define VERSION_REVISION 34 |
| 35 | // server info. | 35 | // server info. |
| 36 | #define RTMP_SIG_SRS_KEY "SRS" | 36 | #define RTMP_SIG_SRS_KEY "SRS" |
| 37 | #define RTMP_SIG_SRS_ROLE "origin/edge server" | 37 | #define RTMP_SIG_SRS_ROLE "origin/edge server" |
| @@ -73,11 +73,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -73,11 +73,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 73 | #endif | 73 | #endif |
| 74 | 74 | ||
| 75 | // for srs-librtmp, @see https://github.com/winlinvip/simple-rtmp-server/issues/213 | 75 | // for srs-librtmp, @see https://github.com/winlinvip/simple-rtmp-server/issues/213 |
| 76 | -#if defined(_WIN32) | ||
| 77 | - #include <windows.h> | ||
| 78 | -#endif | ||
| 79 | - | ||
| 80 | -// for srs-librtmp, @see https://github.com/winlinvip/simple-rtmp-server/issues/213 | ||
| 81 | #ifndef _WIN32 | 76 | #ifndef _WIN32 |
| 82 | #include <inttypes.h> | 77 | #include <inttypes.h> |
| 83 | #endif | 78 | #endif |
| @@ -115,9 +110,5 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -115,9 +110,5 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 115 | className(const className&); \ | 110 | className(const className&); \ |
| 116 | className& operator= (const className&) | 111 | className& operator= (const className&) |
| 117 | 112 | ||
| 118 | -// for windows to compile srs-librtmp | ||
| 119 | -// @see: https://github.com/winlinvip/simple-rtmp-server/issues/213 | ||
| 120 | -#include <srs_platform.hpp> | ||
| 121 | - | ||
| 122 | #endif | 113 | #endif |
| 123 | 114 |
trunk/src/core/srs_platform.cpp
已删除
100644 → 0
| 1 | -/* | ||
| 2 | -The MIT License (MIT) | ||
| 3 | - | ||
| 4 | -Copyright (c) 2014 allspace | ||
| 5 | - | ||
| 6 | -Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| 7 | -this software and associated documentation files (the "Software"), to deal in | ||
| 8 | -the Software without restriction, including without limitation the rights to | ||
| 9 | -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| 10 | -the Software, and to permit persons to whom the Software is furnished to do so, | ||
| 11 | -subject to the following conditions: | ||
| 12 | - | ||
| 13 | -The above copyright notice and this permission notice shall be included in all | ||
| 14 | -copies or substantial portions of the Software. | ||
| 15 | - | ||
| 16 | -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| 18 | -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| 19 | -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| 20 | -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 22 | -*/ | ||
| 23 | - | ||
| 24 | -#include <srs_platform.hpp> | ||
| 25 | - | ||
| 26 | -#include <stdlib.h> | ||
| 27 | -#include <stdio.h> | ||
| 28 | -#include <sys/types.h> | ||
| 29 | - | ||
| 30 | -#if defined(_WIN32) && !defined(__CYGWIN__) | ||
| 31 | -int socket_setup() | ||
| 32 | -{ | ||
| 33 | - WORD wVersionRequested; | ||
| 34 | - WSADATA wsaData; | ||
| 35 | - int err; | ||
| 36 | - | ||
| 37 | - /* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */ | ||
| 38 | - wVersionRequested = MAKEWORD(2, 2); | ||
| 39 | - | ||
| 40 | - err = WSAStartup(wVersionRequested, &wsaData); | ||
| 41 | - if (err != 0) { | ||
| 42 | - /* Tell the user that we could not find a usable */ | ||
| 43 | - /* Winsock DLL. */ | ||
| 44 | - //printf("WSAStartup failed with error: %d\n", err); | ||
| 45 | - return -1; | ||
| 46 | - } | ||
| 47 | - return 0; | ||
| 48 | -} | ||
| 49 | - | ||
| 50 | -int socket_cleanup() | ||
| 51 | -{ | ||
| 52 | - WSACleanup(); | ||
| 53 | - return 0; | ||
| 54 | -} | ||
| 55 | - | ||
| 56 | -int gettimeofday(struct timeval* tv, struct timezone* tz) | ||
| 57 | -{ | ||
| 58 | - time_t clock; | ||
| 59 | - struct tm tm; | ||
| 60 | - SYSTEMTIME win_time; | ||
| 61 | - | ||
| 62 | - GetLocalTime(&win_time); | ||
| 63 | - | ||
| 64 | - tm.tm_year = win_time.wYear - 1900; | ||
| 65 | - tm.tm_mon = win_time.wMonth - 1; | ||
| 66 | - tm.tm_mday = win_time.wDay; | ||
| 67 | - tm.tm_hour = win_time.wHour; | ||
| 68 | - tm.tm_min = win_time.wMinute; | ||
| 69 | - tm.tm_sec = win_time.wSecond; | ||
| 70 | - tm.tm_isdst = -1; | ||
| 71 | - | ||
| 72 | - clock = mktime(&tm); | ||
| 73 | - | ||
| 74 | - tv->tv_sec = (long)clock; | ||
| 75 | - tv->tv_usec = win_time.wMilliseconds * 1000; | ||
| 76 | - | ||
| 77 | - return 0; | ||
| 78 | -} | ||
| 79 | - | ||
| 80 | -pid_t getpid(void) | ||
| 81 | -{ | ||
| 82 | - return (pid_t)GetCurrentProcessId(); | ||
| 83 | -} | ||
| 84 | - | ||
| 85 | -int usleep(useconds_t usec) | ||
| 86 | -{ | ||
| 87 | - Sleep((DWORD)(usec / 1000)); | ||
| 88 | - return 0; | ||
| 89 | -} | ||
| 90 | - | ||
| 91 | -ssize_t writev(int fd, const struct iovec *iov, int iovcnt) | ||
| 92 | -{ | ||
| 93 | - ssize_t nwrite = 0; | ||
| 94 | - for (int i = 0; i < iovcnt; i++) { | ||
| 95 | - const struct iovec* current = iov + i; | ||
| 96 | - | ||
| 97 | - int nsent = ::send(fd, (char*)current->iov_base, current->iov_len, 0); | ||
| 98 | - if (nsent < 0) { | ||
| 99 | - return nsent; | ||
| 100 | - } | ||
| 101 | - | ||
| 102 | - nwrite += nsent; | ||
| 103 | - if (nsent == 0) { | ||
| 104 | - return nwrite; | ||
| 105 | - } | ||
| 106 | - } | ||
| 107 | - return nwrite; | ||
| 108 | -} | ||
| 109 | - | ||
| 110 | -//////////////////////// strlcpy.c (modified) ////////////////////////// | ||
| 111 | - | ||
| 112 | -/* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */ | ||
| 113 | - | ||
| 114 | -/*- | ||
| 115 | - * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> | ||
| 116 | - * | ||
| 117 | - * Permission to use, copy, modify, and distribute this software for any | ||
| 118 | - * purpose with or without fee is hereby granted, provided that the above | ||
| 119 | - * copyright notice and this permission notice appear in all copies. | ||
| 120 | - * | ||
| 121 | - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 122 | - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 123 | - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 124 | - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 125 | - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 126 | - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 127 | - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 128 | - */ | ||
| 129 | - | ||
| 130 | -//#include <sys/cdefs.h> // **** | ||
| 131 | -//#include <cstddef> // **** | ||
| 132 | -// __FBSDID("$FreeBSD: stable/9/sys/libkern/strlcpy.c 243811 2012-12-03 18:08:44Z delphij $"); // **** | ||
| 133 | - | ||
| 134 | -// #include <sys/types.h> // **** | ||
| 135 | -// #include <sys/libkern.h> // **** | ||
| 136 | - | ||
| 137 | -/* | ||
| 138 | - * Copy src to string dst of size siz. At most siz-1 characters | ||
| 139 | - * will be copied. Always NUL terminates (unless siz == 0). | ||
| 140 | - * Returns strlen(src); if retval >= siz, truncation occurred. | ||
| 141 | - */ | ||
| 142 | - | ||
| 143 | -//#define __restrict // **** | ||
| 144 | - | ||
| 145 | -size_t strlcpy(char * __restrict dst, const char * __restrict src, size_t siz) | ||
| 146 | -{ | ||
| 147 | - char *d = dst; | ||
| 148 | - const char *s = src; | ||
| 149 | - size_t n = siz; | ||
| 150 | - | ||
| 151 | - /* Copy as many bytes as will fit */ | ||
| 152 | - if (n != 0) { | ||
| 153 | - while (--n != 0) { | ||
| 154 | - if ((*d++ = *s++) == '\0') | ||
| 155 | - break; | ||
| 156 | - } | ||
| 157 | - } | ||
| 158 | - | ||
| 159 | - /* Not enough room in dst, add NUL and traverse rest of src */ | ||
| 160 | - if (n == 0) { | ||
| 161 | - if (siz != 0) | ||
| 162 | - *d = '\0'; /* NUL-terminate dst */ | ||
| 163 | - while (*s++) | ||
| 164 | - ; | ||
| 165 | - } | ||
| 166 | - | ||
| 167 | - return(s - src - 1); /* count does not include NUL */ | ||
| 168 | -} | ||
| 169 | - | ||
| 170 | -// http://www.cplusplus.com/forum/general/141779///////////////////////// inet_ntop.c (modified) ////////////////////////// | ||
| 171 | -/* | ||
| 172 | - * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") | ||
| 173 | - * Copyright (c) 1996-1999 by Internet Software Consortium. | ||
| 174 | - * | ||
| 175 | - * Permission to use, copy, modify, and distribute this software for any | ||
| 176 | - * purpose with or without fee is hereby granted, provided that the above | ||
| 177 | - * copyright notice and this permission notice appear in all copies. | ||
| 178 | - * | ||
| 179 | - * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES | ||
| 180 | - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 181 | - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR | ||
| 182 | - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 183 | - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 184 | - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT | ||
| 185 | - * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 186 | - */ | ||
| 187 | - | ||
| 188 | -// #if defined(LIBC_SCCS) && !defined(lint) // **** | ||
| 189 | -//static const char rcsid[] = "$Id: inet_ntop.c,v 1.3.18.2 2005/11/03 23:02:22 marka Exp $"; | ||
| 190 | -// #endif /* LIBC_SCCS and not lint */ // **** | ||
| 191 | -// #include <sys/cdefs.h> // **** | ||
| 192 | -// __FBSDID("$FreeBSD: stable/9/sys/libkern/inet_ntop.c 213103 2010-09-24 15:01:45Z attilio $"); // **** | ||
| 193 | - | ||
| 194 | -//#define _WIN32_WINNT _WIN32_WINNT_WIN8 // **** | ||
| 195 | -//#include <Ws2tcpip.h> // **** | ||
| 196 | -//#pragma comment(lib, "Ws2_32.lib") // **** | ||
| 197 | -//#include <cstdio> // **** | ||
| 198 | - | ||
| 199 | -// #include <sys/param.h> // **** | ||
| 200 | -// #include <sys/socket.h> // **** | ||
| 201 | -// #include <sys/systm.h> // **** | ||
| 202 | - | ||
| 203 | -// #include <netinet/in.h> // **** | ||
| 204 | - | ||
| 205 | -/*% | ||
| 206 | - * WARNING: Don't even consider trying to compile this on a system where | ||
| 207 | - * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. | ||
| 208 | - */ | ||
| 209 | - | ||
| 210 | -static char *inet_ntop4(const u_char *src, char *dst, socklen_t size); | ||
| 211 | -static char *inet_ntop6(const u_char *src, char *dst, socklen_t size); | ||
| 212 | - | ||
| 213 | -/* char * | ||
| 214 | - * inet_ntop(af, src, dst, size) | ||
| 215 | - * convert a network format address to presentation format. | ||
| 216 | - * return: | ||
| 217 | - * pointer to presentation format address (`dst'), or NULL (see errno). | ||
| 218 | - * author: | ||
| 219 | - * Paul Vixie, 1996. | ||
| 220 | - */ | ||
| 221 | -const char* inet_ntop(int af, const void *src, char *dst, socklen_t size) | ||
| 222 | -{ | ||
| 223 | - switch (af) { | ||
| 224 | - case AF_INET: | ||
| 225 | - return (inet_ntop4( (unsigned char*)src, (char*)dst, size)); // **** | ||
| 226 | -#ifdef AF_INET6 | ||
| 227 | - //#error "IPv6 not supported" | ||
| 228 | - //case AF_INET6: | ||
| 229 | - // return (char*)(inet_ntop6( (unsigned char*)src, (char*)dst, size)); // **** | ||
| 230 | -#endif | ||
| 231 | - default: | ||
| 232 | - // return (NULL); // **** | ||
| 233 | - return 0 ; // **** | ||
| 234 | - } | ||
| 235 | - /* NOTREACHED */ | ||
| 236 | -} | ||
| 237 | - | ||
| 238 | -/* const char * | ||
| 239 | - * inet_ntop4(src, dst, size) | ||
| 240 | - * format an IPv4 address | ||
| 241 | - * return: | ||
| 242 | - * `dst' (as a const) | ||
| 243 | - * notes: | ||
| 244 | - * (1) uses no statics | ||
| 245 | - * (2) takes a u_char* not an in_addr as input | ||
| 246 | - * author: | ||
| 247 | - * Paul Vixie, 1996. | ||
| 248 | - */ | ||
| 249 | -static char * inet_ntop4(const u_char *src, char *dst, socklen_t size) | ||
| 250 | -{ | ||
| 251 | - static const char fmt[128] = "%u.%u.%u.%u"; | ||
| 252 | - char tmp[sizeof "255.255.255.255"]; | ||
| 253 | - int l; | ||
| 254 | - | ||
| 255 | - l = snprintf(tmp, sizeof(tmp), fmt, src[0], src[1], src[2], src[3]); // **** | ||
| 256 | - if (l <= 0 || (socklen_t) l >= size) { | ||
| 257 | - return (NULL); | ||
| 258 | - } | ||
| 259 | - strlcpy(dst, tmp, size); | ||
| 260 | - return (dst); | ||
| 261 | -} | ||
| 262 | - | ||
| 263 | -/* const char * | ||
| 264 | - * inet_ntop6(src, dst, size) | ||
| 265 | - * convert IPv6 binary address into presentation (printable) format | ||
| 266 | - * author: | ||
| 267 | - * Paul Vixie, 1996. | ||
| 268 | - */ | ||
| 269 | -static char * inet_ntop6(const u_char *src, char *dst, socklen_t size) | ||
| 270 | -{ | ||
| 271 | - /* | ||
| 272 | - * Note that int32_t and int16_t need only be "at least" large enough | ||
| 273 | - * to contain a value of the specified size. On some systems, like | ||
| 274 | - * Crays, there is no such thing as an integer variable with 16 bits. | ||
| 275 | - * Keep this in mind if you think this function should have been coded | ||
| 276 | - * to use pointer overlays. All the world's not a VAX. | ||
| 277 | - */ | ||
| 278 | - char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp; | ||
| 279 | - struct { int base, len; } best, cur; | ||
| 280 | -#define NS_IN6ADDRSZ 16 | ||
| 281 | -#define NS_INT16SZ 2 | ||
| 282 | - u_int words[NS_IN6ADDRSZ / NS_INT16SZ]; | ||
| 283 | - int i; | ||
| 284 | - | ||
| 285 | - /* | ||
| 286 | - * Preprocess: | ||
| 287 | - * Copy the input (bytewise) array into a wordwise array. | ||
| 288 | - * Find the longest run of 0x00's in src[] for :: shorthanding. | ||
| 289 | - */ | ||
| 290 | - memset(words, '\0', sizeof words); | ||
| 291 | - for (i = 0; i < NS_IN6ADDRSZ; i++) | ||
| 292 | - words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3)); | ||
| 293 | - best.base = -1; | ||
| 294 | - best.len = 0; | ||
| 295 | - cur.base = -1; | ||
| 296 | - cur.len = 0; | ||
| 297 | - for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { | ||
| 298 | - if (words[i] == 0) { | ||
| 299 | - if (cur.base == -1) | ||
| 300 | - cur.base = i, cur.len = 1; | ||
| 301 | - else | ||
| 302 | - cur.len++; | ||
| 303 | - } else { | ||
| 304 | - if (cur.base != -1) { | ||
| 305 | - if (best.base == -1 || cur.len > best.len) | ||
| 306 | - best = cur; | ||
| 307 | - cur.base = -1; | ||
| 308 | - } | ||
| 309 | - } | ||
| 310 | - } | ||
| 311 | - if (cur.base != -1) { | ||
| 312 | - if (best.base == -1 || cur.len > best.len) | ||
| 313 | - best = cur; | ||
| 314 | - } | ||
| 315 | - if (best.base != -1 && best.len < 2) | ||
| 316 | - best.base = -1; | ||
| 317 | - | ||
| 318 | - /* | ||
| 319 | - * Format the result. | ||
| 320 | - */ | ||
| 321 | - tp = tmp; | ||
| 322 | - for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { | ||
| 323 | - /* Are we inside the best run of 0x00's? */ | ||
| 324 | - if (best.base != -1 && i >= best.base && | ||
| 325 | - i < (best.base + best.len)) { | ||
| 326 | - if (i == best.base) | ||
| 327 | - *tp++ = ':'; | ||
| 328 | - continue; | ||
| 329 | - } | ||
| 330 | - /* Are we following an initial run of 0x00s or any real hex? */ | ||
| 331 | - if (i != 0) | ||
| 332 | - *tp++ = ':'; | ||
| 333 | - /* Is this address an encapsulated IPv4? */ | ||
| 334 | - if (i == 6 && best.base == 0 && (best.len == 6 || | ||
| 335 | - (best.len == 7 && words[7] != 0x0001) || | ||
| 336 | - (best.len == 5 && words[5] == 0xffff))) { | ||
| 337 | - if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp))) | ||
| 338 | - return (NULL); | ||
| 339 | - tp += strlen(tp); | ||
| 340 | - break; | ||
| 341 | - } | ||
| 342 | - tp += sprintf(tp, "%x", words[i]); // **** | ||
| 343 | - } | ||
| 344 | - /* Was it a trailing run of 0x00's? */ | ||
| 345 | - if (best.base != -1 && (best.base + best.len) == | ||
| 346 | - (NS_IN6ADDRSZ / NS_INT16SZ)) | ||
| 347 | - *tp++ = ':'; | ||
| 348 | - *tp++ = '\0'; | ||
| 349 | - | ||
| 350 | - /* | ||
| 351 | - * Check for overflow, copy, and we're done. | ||
| 352 | - */ | ||
| 353 | - if ((socklen_t)(tp - tmp) > size) { | ||
| 354 | - return (NULL); | ||
| 355 | - } | ||
| 356 | - strcpy(dst, tmp); | ||
| 357 | - return (dst); | ||
| 358 | -} | ||
| 359 | - | ||
| 360 | -#define Set_errno(num) SetLastError((num)) | ||
| 361 | - | ||
| 362 | -/* INVALID_SOCKET == INVALID_HANDLE_VALUE == (unsigned int)(~0) */ | ||
| 363 | -/* SOCKET_ERROR == -1 */ | ||
| 364 | -//#define ENOTSOCK WSAENOTSOCK | ||
| 365 | -//#define EINTR WSAEINTR | ||
| 366 | -//#define ENOBUFS WSAENOBUFS | ||
| 367 | -//#define EWOULDBLOCK WSAEWOULDBLOCK | ||
| 368 | -#define EAFNOSUPPORT WSAEAFNOSUPPORT | ||
| 369 | -/* from public\sdk\inc\crt\errno.h */ | ||
| 370 | -#define ENOSPC 28 | ||
| 371 | - | ||
| 372 | -#endif | ||
| 373 | - |
trunk/src/core/srs_platform.hpp
已删除
100644 → 0
| 1 | -/* | ||
| 2 | -The MIT License (MIT) | ||
| 3 | - | ||
| 4 | -Copyright (c) 2014 allspace | ||
| 5 | - | ||
| 6 | -Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| 7 | -this software and associated documentation files (the "Software"), to deal in | ||
| 8 | -the Software without restriction, including without limitation the rights to | ||
| 9 | -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| 10 | -the Software, and to permit persons to whom the Software is furnished to do so, | ||
| 11 | -subject to the following conditions: | ||
| 12 | - | ||
| 13 | -The above copyright notice and this permission notice shall be included in all | ||
| 14 | -copies or substantial portions of the Software. | ||
| 15 | - | ||
| 16 | -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| 18 | -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| 19 | -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| 20 | -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 22 | -*/ | ||
| 23 | - | ||
| 24 | -#ifndef SRS_WIN_PORTING_H | ||
| 25 | -#define SRS_WIN_PORTING_H | ||
| 26 | - | ||
| 27 | -/** | ||
| 28 | -* for linux like, | ||
| 29 | -* for example, not on windows or it's cygwin. | ||
| 30 | -* while the _WIN32 includes both 32-bit and 64-bit | ||
| 31 | -*/ | ||
| 32 | -#if !defined(_WIN32) || defined(__CYGWIN__) | ||
| 33 | - #define SOCKET_ETIME ETIME | ||
| 34 | - #define SOCKET_ECONNRESET ECONNRESET | ||
| 35 | - | ||
| 36 | - #define SOCKET int | ||
| 37 | - #define SOCKET_ERRNO() errno | ||
| 38 | - #define SOCKET_RESET(fd) fd = -1; (void)0 | ||
| 39 | - #define SOCKET_CLOSE(fd) \ | ||
| 40 | - if (fd > 0) {\ | ||
| 41 | - ::close(fd); \ | ||
| 42 | - fd = -1; \ | ||
| 43 | - } \ | ||
| 44 | - (void)0 | ||
| 45 | - #define SOCKET_VALID(x) (x > 0) | ||
| 46 | - #define SOCKET_SETUP() (void)0 | ||
| 47 | - #define SOCKET_CLEANUP() (void)0 | ||
| 48 | -#else /*on windows, but not on cygwin*/ | ||
| 49 | - #include <sys/stat.h> | ||
| 50 | - #include <time.h> | ||
| 51 | - #include <winsock2.h> | ||
| 52 | - #include <stdint.h> | ||
| 53 | - | ||
| 54 | - #ifdef _MSC_VER //for VS2010 | ||
| 55 | - #include <io.h> | ||
| 56 | - #include <fcntl.h> | ||
| 57 | - #define S_IRUSR _S_IREAD | ||
| 58 | - #define S_IWUSR _S_IWRITE | ||
| 59 | - #define open _open | ||
| 60 | - #define close _close | ||
| 61 | - #define lseek _lseek | ||
| 62 | - #define write _write | ||
| 63 | - #define read _read | ||
| 64 | - | ||
| 65 | - typedef int ssize_t; | ||
| 66 | - typedef int pid_t; | ||
| 67 | - typedef int mode_t; | ||
| 68 | - typedef int64_t useconds_t; | ||
| 69 | - #endif | ||
| 70 | - | ||
| 71 | - #define S_IRGRP 0 | ||
| 72 | - #define S_IWGRP 0 | ||
| 73 | - #define S_IXGRP 0 | ||
| 74 | - #define S_IRWXG 0 | ||
| 75 | - #define S_IROTH 0 | ||
| 76 | - #define S_IWOTH 0 | ||
| 77 | - #define S_IXOTH 0 | ||
| 78 | - #define S_IRWXO 0 | ||
| 79 | - | ||
| 80 | - #define PRId64 "lld" | ||
| 81 | - | ||
| 82 | - #define SOCKET_ETIME WSAETIMEDOUT | ||
| 83 | - #define SOCKET_ECONNRESET WSAECONNRESET | ||
| 84 | - #define SOCKET_ERRNO() WSAGetLastError() | ||
| 85 | - #define SOCKET_RESET(x) x=INVALID_SOCKET | ||
| 86 | - #define SOCKET_CLOSE(x) if(x!=INVALID_SOCKET){::closesocket(x);x=INVALID_SOCKET;} | ||
| 87 | - #define SOCKET_VALID(x) (x!=INVALID_SOCKET) | ||
| 88 | - #define SOCKET_BUFF(x) ((char*)x) | ||
| 89 | - #define SOCKET_SETUP() socket_setup() | ||
| 90 | - #define SOCKET_CLEANUP() socket_cleanup() | ||
| 91 | - | ||
| 92 | - typedef uint32_t u_int32_t; | ||
| 93 | - typedef uint8_t u_int8_t; | ||
| 94 | - typedef int socklen_t; | ||
| 95 | - struct iovec { | ||
| 96 | - void* iov_base; /* Starting address */ | ||
| 97 | - size_t iov_len; /* Length in bytes */ | ||
| 98 | - }; | ||
| 99 | - | ||
| 100 | - #define snprintf _snprintf | ||
| 101 | - ssize_t writev(int fd, const struct iovec *iov, int iovcnt); | ||
| 102 | - const char* inet_ntop(int af, const void *src, char *dst, socklen_t size); | ||
| 103 | - int gettimeofday(struct timeval* tv, struct timezone* tz); | ||
| 104 | - pid_t getpid(void); | ||
| 105 | - int usleep(useconds_t usec); | ||
| 106 | - int socket_setup(); | ||
| 107 | - int socket_cleanup(); | ||
| 108 | -#endif | ||
| 109 | - | ||
| 110 | -#endif //SRS_WIN_PORTING_H |
| @@ -45,22 +45,22 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -45,22 +45,22 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 45 | 45 | ||
| 46 | SimpleSocketStream::SimpleSocketStream() | 46 | SimpleSocketStream::SimpleSocketStream() |
| 47 | { | 47 | { |
| 48 | - SOCKET_RESET(fd); | 48 | + fd = -1; |
| 49 | send_timeout = recv_timeout = ST_UTIME_NO_TIMEOUT; | 49 | send_timeout = recv_timeout = ST_UTIME_NO_TIMEOUT; |
| 50 | recv_bytes = send_bytes = 0; | 50 | recv_bytes = send_bytes = 0; |
| 51 | - SOCKET_SETUP(); | ||
| 52 | } | 51 | } |
| 53 | 52 | ||
| 54 | SimpleSocketStream::~SimpleSocketStream() | 53 | SimpleSocketStream::~SimpleSocketStream() |
| 55 | { | 54 | { |
| 56 | - SOCKET_CLOSE(fd); | ||
| 57 | - SOCKET_CLEANUP(); | 55 | + if (fd != -1) { |
| 56 | + ::close(fd); | ||
| 57 | + fd = -1; | ||
| 58 | + } | ||
| 58 | } | 59 | } |
| 59 | 60 | ||
| 60 | int SimpleSocketStream::create_socket() | 61 | int SimpleSocketStream::create_socket() |
| 61 | { | 62 | { |
| 62 | - fd = ::socket(AF_INET, SOCK_STREAM, 0); | ||
| 63 | - if (!SOCKET_VALID(fd)) { | 63 | + if((fd = ::socket(AF_INET, SOCK_STREAM, 0)) < 0){ |
| 64 | return ERROR_SOCKET_CREATE; | 64 | return ERROR_SOCKET_CREATE; |
| 65 | } | 65 | } |
| 66 | 66 | ||
| @@ -95,12 +95,12 @@ int SimpleSocketStream::read(void* buf, size_t size, ssize_t* nread) | @@ -95,12 +95,12 @@ int SimpleSocketStream::read(void* buf, size_t size, ssize_t* nread) | ||
| 95 | // On success a non-negative integer indicating the number of bytes actually read is returned | 95 | // On success a non-negative integer indicating the number of bytes actually read is returned |
| 96 | // (a value of 0 means the network connection is closed or end of file is reached). | 96 | // (a value of 0 means the network connection is closed or end of file is reached). |
| 97 | if (nb_read <= 0) { | 97 | if (nb_read <= 0) { |
| 98 | - if (nb_read < 0 && SOCKET_ERRNO() == SOCKET_ETIME) { | 98 | + if (nb_read < 0 && errno == ETIME) { |
| 99 | return ERROR_SOCKET_TIMEOUT; | 99 | return ERROR_SOCKET_TIMEOUT; |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | if (nb_read == 0) { | 102 | if (nb_read == 0) { |
| 103 | - errno = SOCKET_ECONNRESET; | 103 | + errno = ECONNRESET; |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | return ERROR_SOCKET_READ; | 106 | return ERROR_SOCKET_READ; |
| @@ -158,7 +158,7 @@ int SimpleSocketStream::writev(const iovec *iov, int iov_size, ssize_t* nwrite) | @@ -158,7 +158,7 @@ int SimpleSocketStream::writev(const iovec *iov, int iov_size, ssize_t* nwrite) | ||
| 158 | // returned, and errno is set appropriately. | 158 | // returned, and errno is set appropriately. |
| 159 | if (nb_write <= 0) { | 159 | if (nb_write <= 0) { |
| 160 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/200 | 160 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/200 |
| 161 | - if (nb_write < 0 && SOCKET_ERRNO() == SOCKET_ETIME) { | 161 | + if (nb_write < 0 && errno == ETIME) { |
| 162 | return ERROR_SOCKET_TIMEOUT; | 162 | return ERROR_SOCKET_TIMEOUT; |
| 163 | } | 163 | } |
| 164 | 164 | ||
| @@ -215,7 +215,7 @@ int SimpleSocketStream::write(void* buf, size_t size, ssize_t* nwrite) | @@ -215,7 +215,7 @@ int SimpleSocketStream::write(void* buf, size_t size, ssize_t* nwrite) | ||
| 215 | 215 | ||
| 216 | if (nb_write <= 0) { | 216 | if (nb_write <= 0) { |
| 217 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/200 | 217 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/200 |
| 218 | - if (nb_write < 0 && SOCKET_ERRNO() == SOCKET_ETIME) { | 218 | + if (nb_write < 0 && errno == ETIME) { |
| 219 | return ERROR_SOCKET_TIMEOUT; | 219 | return ERROR_SOCKET_TIMEOUT; |
| 220 | } | 220 | } |
| 221 | 221 |
| @@ -43,7 +43,7 @@ private: | @@ -43,7 +43,7 @@ private: | ||
| 43 | int64_t send_timeout; | 43 | int64_t send_timeout; |
| 44 | int64_t recv_bytes; | 44 | int64_t recv_bytes; |
| 45 | int64_t send_bytes; | 45 | int64_t send_bytes; |
| 46 | - SOCKET fd; | 46 | + int fd; |
| 47 | public: | 47 | public: |
| 48 | SimpleSocketStream(); | 48 | SimpleSocketStream(); |
| 49 | virtual ~SimpleSocketStream(); | 49 | virtual ~SimpleSocketStream(); |
| @@ -34,7 +34,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -34,7 +34,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 34 | #include <sstream> | 34 | #include <sstream> |
| 35 | using namespace std; | 35 | using namespace std; |
| 36 | 36 | ||
| 37 | -#include <srs_platform.hpp> | ||
| 38 | #include <srs_kernel_error.hpp> | 37 | #include <srs_kernel_error.hpp> |
| 39 | #include <srs_protocol_rtmp.hpp> | 38 | #include <srs_protocol_rtmp.hpp> |
| 40 | #include <srs_lib_simple_socket.hpp> | 39 | #include <srs_lib_simple_socket.hpp> |
| @@ -108,6 +107,356 @@ struct Context | @@ -108,6 +107,356 @@ struct Context | ||
| 108 | } | 107 | } |
| 109 | }; | 108 | }; |
| 110 | 109 | ||
| 110 | +// for srs-librtmp, @see https://github.com/winlinvip/simple-rtmp-server/issues/213 | ||
| 111 | +#ifdef _WIN32 | ||
| 112 | + int gettimeofday(struct timeval* tv, struct timezone* tz) | ||
| 113 | + { | ||
| 114 | + time_t clock; | ||
| 115 | + struct tm tm; | ||
| 116 | + SYSTEMTIME win_time; | ||
| 117 | + | ||
| 118 | + GetLocalTime(&win_time); | ||
| 119 | + | ||
| 120 | + tm.tm_year = win_time.wYear - 1900; | ||
| 121 | + tm.tm_mon = win_time.wMonth - 1; | ||
| 122 | + tm.tm_mday = win_time.wDay; | ||
| 123 | + tm.tm_hour = win_time.wHour; | ||
| 124 | + tm.tm_min = win_time.wMinute; | ||
| 125 | + tm.tm_sec = win_time.wSecond; | ||
| 126 | + tm.tm_isdst = -1; | ||
| 127 | + | ||
| 128 | + clock = mktime(&tm); | ||
| 129 | + | ||
| 130 | + tv->tv_sec = (long)clock; | ||
| 131 | + tv->tv_usec = win_time.wMilliseconds * 1000; | ||
| 132 | + | ||
| 133 | + return 0; | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + int open(const char *pathname, int flags) | ||
| 137 | + { | ||
| 138 | + return open(pathname, flags, 0); | ||
| 139 | + } | ||
| 140 | + | ||
| 141 | + int open(const char *pathname, int flags, mode_t mode) | ||
| 142 | + { | ||
| 143 | + FILE* file = NULL; | ||
| 144 | + | ||
| 145 | + if ((flags & O_RDONLY) == O_RDONLY) { | ||
| 146 | + file = fopen(pathname, "r"); | ||
| 147 | + } else { | ||
| 148 | + file = fopen(pathname, "w+"); | ||
| 149 | + } | ||
| 150 | + | ||
| 151 | + if (file == NULL) { | ||
| 152 | + return -1; | ||
| 153 | + } | ||
| 154 | + | ||
| 155 | + return (int)file; | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | + int close(int fd) | ||
| 159 | + { | ||
| 160 | + FILE* file = (FILE*)fd; | ||
| 161 | + return fclose(file); | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + off_t lseek(int fd, off_t offset, int whence) | ||
| 165 | + { | ||
| 166 | + return (off_t)fseek((FILE*)fd, offset, whence); | ||
| 167 | + } | ||
| 168 | + | ||
| 169 | + ssize_t write(int fd, const void *buf, size_t count) | ||
| 170 | + { | ||
| 171 | + return (ssize_t)fwrite(buf, count, 1, (FILE*)fd); | ||
| 172 | + } | ||
| 173 | + | ||
| 174 | + ssize_t read(int fd, void *buf, size_t count) | ||
| 175 | + { | ||
| 176 | + return (ssize_t)fread(buf, count, 1, (FILE*)fd); | ||
| 177 | + } | ||
| 178 | + | ||
| 179 | + pid_t getpid(void) | ||
| 180 | + { | ||
| 181 | + return (pid_t)GetCurrentProcessId(); | ||
| 182 | + } | ||
| 183 | + | ||
| 184 | + int usleep(useconds_t usec) | ||
| 185 | + { | ||
| 186 | + Sleep((DWORD)(usec / 1000)); | ||
| 187 | + return 0; | ||
| 188 | + } | ||
| 189 | + | ||
| 190 | + ssize_t writev(int fd, const struct iovec *iov, int iovcnt) | ||
| 191 | + { | ||
| 192 | + ssize_t nwrite = 0; | ||
| 193 | + for (int i = 0; i < iovcnt; i++) { | ||
| 194 | + const struct iovec* current = iov + i; | ||
| 195 | + | ||
| 196 | + int nsent = ::send(fd, (char*)current->iov_base, current->iov_len, 0); | ||
| 197 | + if (nsent < 0) { | ||
| 198 | + return nsent; | ||
| 199 | + } | ||
| 200 | + | ||
| 201 | + nwrite += nsent; | ||
| 202 | + if (nsent == 0) { | ||
| 203 | + return nwrite; | ||
| 204 | + } | ||
| 205 | + } | ||
| 206 | + return nwrite; | ||
| 207 | + } | ||
| 208 | + | ||
| 209 | + //////////////////////// strlcpy.c (modified) ////////////////////////// | ||
| 210 | + | ||
| 211 | + /* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */ | ||
| 212 | + | ||
| 213 | + /*- | ||
| 214 | + * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> | ||
| 215 | + * | ||
| 216 | + * Permission to use, copy, modify, and distribute this software for any | ||
| 217 | + * purpose with or without fee is hereby granted, provided that the above | ||
| 218 | + * copyright notice and this permission notice appear in all copies. | ||
| 219 | + * | ||
| 220 | + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 221 | + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 222 | + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 223 | + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 224 | + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 225 | + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 226 | + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 227 | + */ | ||
| 228 | + | ||
| 229 | + //#include <sys/cdefs.h> // **** | ||
| 230 | + //#include <cstddef> // **** | ||
| 231 | + // __FBSDID("$FreeBSD: stable/9/sys/libkern/strlcpy.c 243811 2012-12-03 18:08:44Z delphij $"); // **** | ||
| 232 | + | ||
| 233 | + // #include <sys/types.h> // **** | ||
| 234 | + // #include <sys/libkern.h> // **** | ||
| 235 | + | ||
| 236 | + /* | ||
| 237 | + * Copy src to string dst of size siz. At most siz-1 characters | ||
| 238 | + * will be copied. Always NUL terminates (unless siz == 0). | ||
| 239 | + * Returns strlen(src); if retval >= siz, truncation occurred. | ||
| 240 | + */ | ||
| 241 | + | ||
| 242 | + //#define __restrict // **** | ||
| 243 | + | ||
| 244 | + std::size_t strlcpy(char * __restrict dst, const char * __restrict src, size_t siz) | ||
| 245 | + { | ||
| 246 | + char *d = dst; | ||
| 247 | + const char *s = src; | ||
| 248 | + size_t n = siz; | ||
| 249 | + | ||
| 250 | + /* Copy as many bytes as will fit */ | ||
| 251 | + if (n != 0) { | ||
| 252 | + while (--n != 0) { | ||
| 253 | + if ((*d++ = *s++) == '\0') | ||
| 254 | + break; | ||
| 255 | + } | ||
| 256 | + } | ||
| 257 | + | ||
| 258 | + /* Not enough room in dst, add NUL and traverse rest of src */ | ||
| 259 | + if (n == 0) { | ||
| 260 | + if (siz != 0) | ||
| 261 | + *d = '\0'; /* NUL-terminate dst */ | ||
| 262 | + while (*s++) | ||
| 263 | + ; | ||
| 264 | + } | ||
| 265 | + | ||
| 266 | + return(s - src - 1); /* count does not include NUL */ | ||
| 267 | + } | ||
| 268 | + | ||
| 269 | + // http://www.cplusplus.com/forum/general/141779///////////////////////// inet_ntop.c (modified) ////////////////////////// | ||
| 270 | + /* | ||
| 271 | + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") | ||
| 272 | + * Copyright (c) 1996-1999 by Internet Software Consortium. | ||
| 273 | + * | ||
| 274 | + * Permission to use, copy, modify, and distribute this software for any | ||
| 275 | + * purpose with or without fee is hereby granted, provided that the above | ||
| 276 | + * copyright notice and this permission notice appear in all copies. | ||
| 277 | + * | ||
| 278 | + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES | ||
| 279 | + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 280 | + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR | ||
| 281 | + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 282 | + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 283 | + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT | ||
| 284 | + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 285 | + */ | ||
| 286 | + | ||
| 287 | + // #if defined(LIBC_SCCS) && !defined(lint) // **** | ||
| 288 | + //static const char rcsid[] = "$Id: inet_ntop.c,v 1.3.18.2 2005/11/03 23:02:22 marka Exp $"; | ||
| 289 | + // #endif /* LIBC_SCCS and not lint */ // **** | ||
| 290 | + // #include <sys/cdefs.h> // **** | ||
| 291 | + // __FBSDID("$FreeBSD: stable/9/sys/libkern/inet_ntop.c 213103 2010-09-24 15:01:45Z attilio $"); // **** | ||
| 292 | + | ||
| 293 | + //#define _WIN32_WINNT _WIN32_WINNT_WIN8 // **** | ||
| 294 | + //#include <Ws2tcpip.h> // **** | ||
| 295 | + #pragma comment(lib, "Ws2_32.lib") // **** | ||
| 296 | + //#include <cstdio> // **** | ||
| 297 | + | ||
| 298 | + // #include <sys/param.h> // **** | ||
| 299 | + // #include <sys/socket.h> // **** | ||
| 300 | + // #include <sys/systm.h> // **** | ||
| 301 | + | ||
| 302 | + // #include <netinet/in.h> // **** | ||
| 303 | + | ||
| 304 | + /*% | ||
| 305 | + * WARNING: Don't even consider trying to compile this on a system where | ||
| 306 | + * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. | ||
| 307 | + */ | ||
| 308 | + | ||
| 309 | + static char *inet_ntop4(const u_char *src, char *dst, socklen_t size); | ||
| 310 | + static char *inet_ntop6(const u_char *src, char *dst, socklen_t size); | ||
| 311 | + | ||
| 312 | + /* char * | ||
| 313 | + * inet_ntop(af, src, dst, size) | ||
| 314 | + * convert a network format address to presentation format. | ||
| 315 | + * return: | ||
| 316 | + * pointer to presentation format address (`dst'), or NULL (see errno). | ||
| 317 | + * author: | ||
| 318 | + * Paul Vixie, 1996. | ||
| 319 | + */ | ||
| 320 | + const char* inet_ntop(int af, const void *src, char *dst, socklen_t size) | ||
| 321 | + { | ||
| 322 | + switch (af) { | ||
| 323 | + case AF_INET: | ||
| 324 | + return (inet_ntop4( (unsigned char*)src, (char*)dst, size)); // **** | ||
| 325 | + #ifdef AF_INET6 | ||
| 326 | + #error "IPv6 not supported" | ||
| 327 | + //case AF_INET6: | ||
| 328 | + // return (char*)(inet_ntop6( (unsigned char*)src, (char*)dst, size)); // **** | ||
| 329 | + #endif | ||
| 330 | + default: | ||
| 331 | + // return (NULL); // **** | ||
| 332 | + return 0 ; // **** | ||
| 333 | + } | ||
| 334 | + /* NOTREACHED */ | ||
| 335 | + } | ||
| 336 | + | ||
| 337 | + /* const char * | ||
| 338 | + * inet_ntop4(src, dst, size) | ||
| 339 | + * format an IPv4 address | ||
| 340 | + * return: | ||
| 341 | + * `dst' (as a const) | ||
| 342 | + * notes: | ||
| 343 | + * (1) uses no statics | ||
| 344 | + * (2) takes a u_char* not an in_addr as input | ||
| 345 | + * author: | ||
| 346 | + * Paul Vixie, 1996. | ||
| 347 | + */ | ||
| 348 | + static char * inet_ntop4(const u_char *src, char *dst, socklen_t size) | ||
| 349 | + { | ||
| 350 | + static const char fmt[128] = "%u.%u.%u.%u"; | ||
| 351 | + char tmp[sizeof "255.255.255.255"]; | ||
| 352 | + int l; | ||
| 353 | + | ||
| 354 | + l = snprintf(tmp, sizeof(tmp), fmt, src[0], src[1], src[2], src[3]); // **** | ||
| 355 | + if (l <= 0 || (socklen_t) l >= size) { | ||
| 356 | + return (NULL); | ||
| 357 | + } | ||
| 358 | + strlcpy(dst, tmp, size); | ||
| 359 | + return (dst); | ||
| 360 | + } | ||
| 361 | + | ||
| 362 | + /* const char * | ||
| 363 | + * inet_ntop6(src, dst, size) | ||
| 364 | + * convert IPv6 binary address into presentation (printable) format | ||
| 365 | + * author: | ||
| 366 | + * Paul Vixie, 1996. | ||
| 367 | + */ | ||
| 368 | + static char * inet_ntop6(const u_char *src, char *dst, socklen_t size) | ||
| 369 | + { | ||
| 370 | + /* | ||
| 371 | + * Note that int32_t and int16_t need only be "at least" large enough | ||
| 372 | + * to contain a value of the specified size. On some systems, like | ||
| 373 | + * Crays, there is no such thing as an integer variable with 16 bits. | ||
| 374 | + * Keep this in mind if you think this function should have been coded | ||
| 375 | + * to use pointer overlays. All the world's not a VAX. | ||
| 376 | + */ | ||
| 377 | + char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp; | ||
| 378 | + struct { int base, len; } best, cur; | ||
| 379 | + #define NS_IN6ADDRSZ 16 | ||
| 380 | + #define NS_INT16SZ 2 | ||
| 381 | + u_int words[NS_IN6ADDRSZ / NS_INT16SZ]; | ||
| 382 | + int i; | ||
| 383 | + | ||
| 384 | + /* | ||
| 385 | + * Preprocess: | ||
| 386 | + * Copy the input (bytewise) array into a wordwise array. | ||
| 387 | + * Find the longest run of 0x00's in src[] for :: shorthanding. | ||
| 388 | + */ | ||
| 389 | + memset(words, '\0', sizeof words); | ||
| 390 | + for (i = 0; i < NS_IN6ADDRSZ; i++) | ||
| 391 | + words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3)); | ||
| 392 | + best.base = -1; | ||
| 393 | + best.len = 0; | ||
| 394 | + cur.base = -1; | ||
| 395 | + cur.len = 0; | ||
| 396 | + for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { | ||
| 397 | + if (words[i] == 0) { | ||
| 398 | + if (cur.base == -1) | ||
| 399 | + cur.base = i, cur.len = 1; | ||
| 400 | + else | ||
| 401 | + cur.len++; | ||
| 402 | + } else { | ||
| 403 | + if (cur.base != -1) { | ||
| 404 | + if (best.base == -1 || cur.len > best.len) | ||
| 405 | + best = cur; | ||
| 406 | + cur.base = -1; | ||
| 407 | + } | ||
| 408 | + } | ||
| 409 | + } | ||
| 410 | + if (cur.base != -1) { | ||
| 411 | + if (best.base == -1 || cur.len > best.len) | ||
| 412 | + best = cur; | ||
| 413 | + } | ||
| 414 | + if (best.base != -1 && best.len < 2) | ||
| 415 | + best.base = -1; | ||
| 416 | + | ||
| 417 | + /* | ||
| 418 | + * Format the result. | ||
| 419 | + */ | ||
| 420 | + tp = tmp; | ||
| 421 | + for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { | ||
| 422 | + /* Are we inside the best run of 0x00's? */ | ||
| 423 | + if (best.base != -1 && i >= best.base && | ||
| 424 | + i < (best.base + best.len)) { | ||
| 425 | + if (i == best.base) | ||
| 426 | + *tp++ = ':'; | ||
| 427 | + continue; | ||
| 428 | + } | ||
| 429 | + /* Are we following an initial run of 0x00s or any real hex? */ | ||
| 430 | + if (i != 0) | ||
| 431 | + *tp++ = ':'; | ||
| 432 | + /* Is this address an encapsulated IPv4? */ | ||
| 433 | + if (i == 6 && best.base == 0 && (best.len == 6 || | ||
| 434 | + (best.len == 7 && words[7] != 0x0001) || | ||
| 435 | + (best.len == 5 && words[5] == 0xffff))) { | ||
| 436 | + if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp))) | ||
| 437 | + return (NULL); | ||
| 438 | + tp += strlen(tp); | ||
| 439 | + break; | ||
| 440 | + } | ||
| 441 | + tp += std::sprintf(tp, "%x", words[i]); // **** | ||
| 442 | + } | ||
| 443 | + /* Was it a trailing run of 0x00's? */ | ||
| 444 | + if (best.base != -1 && (best.base + best.len) == | ||
| 445 | + (NS_IN6ADDRSZ / NS_INT16SZ)) | ||
| 446 | + *tp++ = ':'; | ||
| 447 | + *tp++ = '\0'; | ||
| 448 | + | ||
| 449 | + /* | ||
| 450 | + * Check for overflow, copy, and we're done. | ||
| 451 | + */ | ||
| 452 | + if ((socklen_t)(tp - tmp) > size) { | ||
| 453 | + return (NULL); | ||
| 454 | + } | ||
| 455 | + strcpy(dst, tmp); | ||
| 456 | + return (dst); | ||
| 457 | + } | ||
| 458 | +#endif | ||
| 459 | + | ||
| 111 | int srs_librtmp_context_parse_uri(Context* context) | 460 | int srs_librtmp_context_parse_uri(Context* context) |
| 112 | { | 461 | { |
| 113 | int ret = ERROR_SUCCESS; | 462 | int ret = ERROR_SUCCESS; |
| @@ -30,10 +30,46 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -30,10 +30,46 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 30 | 30 | ||
| 31 | #include <sys/types.h> | 31 | #include <sys/types.h> |
| 32 | 32 | ||
| 33 | +// for srs-librtmp, @see https://github.com/winlinvip/simple-rtmp-server/issues/213 | ||
| 33 | #ifdef _WIN32 | 34 | #ifdef _WIN32 |
| 34 | - typedef long int int64_t; | 35 | + #define _CRT_SECURE_NO_WARNINGS |
| 36 | + typedef unsigned long long u_int64_t; | ||
| 37 | + typedef long long int64_t; | ||
| 35 | typedef unsigned int u_int32_t; | 38 | typedef unsigned int u_int32_t; |
| 36 | typedef int int32_t; | 39 | typedef int int32_t; |
| 40 | + typedef unsigned char u_int8_t; | ||
| 41 | + typedef char int8_t; | ||
| 42 | + typedef unsigned short u_int16_t; | ||
| 43 | + typedef short int16_t; | ||
| 44 | + typedef int64_t ssize_t; | ||
| 45 | + struct iovec { | ||
| 46 | + void *iov_base; /* Starting address */ | ||
| 47 | + size_t iov_len; /* Number of bytes to transfer */ | ||
| 48 | + }; | ||
| 49 | + #include <time.h> | ||
| 50 | + #include <windows.h> | ||
| 51 | + int gettimeofday(struct timeval* tv, struct timezone* tz); | ||
| 52 | + #define PRId64 "lld" | ||
| 53 | + typedef int socklen_t; | ||
| 54 | + const char *inet_ntop(int af, const void *src, char *dst, socklen_t size); | ||
| 55 | + typedef int mode_t; | ||
| 56 | + #define S_IRUSR 0 | ||
| 57 | + #define S_IWUSR 0 | ||
| 58 | + #define S_IRGRP 0 | ||
| 59 | + #define S_IWGRP 0 | ||
| 60 | + #define S_IROTH 0 | ||
| 61 | + int open(const char *pathname, int flags); | ||
| 62 | + int open(const char *pathname, int flags, mode_t mode); | ||
| 63 | + int close(int fd); | ||
| 64 | + off_t lseek(int fd, off_t offset, int whence); | ||
| 65 | + ssize_t write(int fd, const void *buf, size_t count); | ||
| 66 | + ssize_t read(int fd, void *buf, size_t count); | ||
| 67 | + typedef int pid_t; | ||
| 68 | + pid_t getpid(void); | ||
| 69 | + #define snprintf _snprintf | ||
| 70 | + ssize_t writev(int fd, const struct iovec *iov, int iovcnt); | ||
| 71 | + typedef int64_t useconds_t; | ||
| 72 | + int usleep(useconds_t usec); | ||
| 37 | #endif | 73 | #endif |
| 38 | 74 | ||
| 39 | /** | 75 | /** |
| @@ -15,8 +15,6 @@ file | @@ -15,8 +15,6 @@ file | ||
| 15 | ..\core\srs_core.cpp, | 15 | ..\core\srs_core.cpp, |
| 16 | ..\core\srs_core_autofree.hpp, | 16 | ..\core\srs_core_autofree.hpp, |
| 17 | ..\core\srs_core_autofree.cpp, | 17 | ..\core\srs_core_autofree.cpp, |
| 18 | - ..\core\srs_platform.hpp, | ||
| 19 | - ..\core\srs_platform.cpp, | ||
| 20 | kernel readonly separator, | 18 | kernel readonly separator, |
| 21 | ..\kernel\srs_kernel_buffer.hpp, | 19 | ..\kernel\srs_kernel_buffer.hpp, |
| 22 | ..\kernel\srs_kernel_buffer.cpp, | 20 | ..\kernel\srs_kernel_buffer.cpp, |
-
请 注册 或 登录 后发表评论