正在显示
11 个修改的文件
包含
409 行增加
和
532 行删除
| @@ -299,10 +299,9 @@ END | @@ -299,10 +299,9 @@ 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 standard. | ||
| 303 | -if [ "$MSYSTEM" != "MINGW32" -a "$MSYSTEM" != "MINGW64" ]; then | ||
| 304 | - CppStd="-ansi" | ||
| 305 | -fi | 302 | +# the compile in c++ standard. |
| 303 | +# @remark, donot specifies it for mingw. | ||
| 304 | +CppStd="-ansi" && echo $MSYSTEM|grep "MINGW">/dev/null && CppStd="" | ||
| 306 | # for library compile | 305 | # for library compile |
| 307 | LibraryCompile=" -fPIC" | 306 | LibraryCompile=" -fPIC" |
| 308 | # performance of gprof | 307 | # performance of gprof |
| @@ -85,7 +85,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -85,7 +85,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 85 | 85 | ||
| 86 | // generated by configure. | 86 | // generated by configure. |
| 87 | #include <srs_auto_headers.hpp> | 87 | #include <srs_auto_headers.hpp> |
| 88 | -#include <srs_platform.hpp> | 88 | + |
| 89 | // free the p and set to NULL. | 89 | // free the p and set to NULL. |
| 90 | // p must be a T*. | 90 | // p must be a T*. |
| 91 | #define srs_freep(p) \ | 91 | #define srs_freep(p) \ |
| @@ -110,5 +110,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -110,5 +110,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 110 | className(const className&); \ | 110 | className(const className&); \ |
| 111 | className& operator= (const className&) | 111 | className& operator= (const className&) |
| 112 | 112 | ||
| 113 | +// for windows to compile srs-librtmp | ||
| 114 | +// @see: https://github.com/winlinvip/simple-rtmp-server/issues/213 | ||
| 115 | +#include <srs_platform.hpp> | ||
| 116 | + | ||
| 113 | #endif | 117 | #endif |
| 114 | 118 |
| 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 | + | ||
| 1 | #include <stdlib.h> | 26 | #include <stdlib.h> |
| 2 | #include <stdio.h> | 27 | #include <stdio.h> |
| 3 | #include <sys/types.h> | 28 | #include <sys/types.h> |
| 4 | -#include "srs_platform.hpp" | ||
| 5 | - | ||
| 6 | 29 | ||
| 7 | #if defined(_WIN32) && !defined(__CYGWIN__) | 30 | #if defined(_WIN32) && !defined(__CYGWIN__) |
| 8 | - | ||
| 9 | int socket_setup() | 31 | int socket_setup() |
| 10 | { | 32 | { |
| 11 | WORD wVersionRequested; | 33 | WORD wVersionRequested; |
| @@ -31,309 +53,309 @@ int socket_cleanup() | @@ -31,309 +53,309 @@ int socket_cleanup() | ||
| 31 | return 0; | 53 | return 0; |
| 32 | } | 54 | } |
| 33 | 55 | ||
| 34 | - int gettimeofday(struct timeval* tv, struct timezone* tz) | ||
| 35 | - { | ||
| 36 | - time_t clock; | ||
| 37 | - struct tm tm; | ||
| 38 | - SYSTEMTIME win_time; | ||
| 39 | - | ||
| 40 | - GetLocalTime(&win_time); | ||
| 41 | - | ||
| 42 | - tm.tm_year = win_time.wYear - 1900; | ||
| 43 | - tm.tm_mon = win_time.wMonth - 1; | ||
| 44 | - tm.tm_mday = win_time.wDay; | ||
| 45 | - tm.tm_hour = win_time.wHour; | ||
| 46 | - tm.tm_min = win_time.wMinute; | ||
| 47 | - tm.tm_sec = win_time.wSecond; | ||
| 48 | - tm.tm_isdst = -1; | ||
| 49 | - | ||
| 50 | - clock = mktime(&tm); | ||
| 51 | - | ||
| 52 | - tv->tv_sec = (long)clock; | ||
| 53 | - tv->tv_usec = win_time.wMilliseconds * 1000; | ||
| 54 | - | ||
| 55 | - return 0; | 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 | + } | ||
| 56 | } | 106 | } |
| 57 | - | ||
| 58 | - pid_t getpid(void) | ||
| 59 | - { | ||
| 60 | - return (pid_t)GetCurrentProcessId(); | 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 | + } | ||
| 61 | } | 157 | } |
| 62 | - | ||
| 63 | - int usleep(useconds_t usec) | ||
| 64 | - { | ||
| 65 | - Sleep((DWORD)(usec / 1000)); | ||
| 66 | - return 0; | 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 | + ; | ||
| 67 | } | 165 | } |
| 68 | - | ||
| 69 | - ssize_t writev(int fd, const struct iovec *iov, int iovcnt) | ||
| 70 | - { | ||
| 71 | - ssize_t nwrite = 0; | ||
| 72 | - for (int i = 0; i < iovcnt; i++) { | ||
| 73 | - const struct iovec* current = iov + i; | ||
| 74 | - | ||
| 75 | - int nsent = ::send(fd, (char*)current->iov_base, current->iov_len, 0); | ||
| 76 | - if (nsent < 0) { | ||
| 77 | - return nsent; | ||
| 78 | - } | ||
| 79 | - | ||
| 80 | - nwrite += nsent; | ||
| 81 | - if (nsent == 0) { | ||
| 82 | - return nwrite; | ||
| 83 | - } | ||
| 84 | - } | ||
| 85 | - return nwrite; | 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 ; // **** | ||
| 86 | } | 234 | } |
| 235 | + /* NOTREACHED */ | ||
| 236 | +} | ||
| 87 | 237 | ||
| 88 | - //////////////////////// strlcpy.c (modified) ////////////////////////// | ||
| 89 | - | ||
| 90 | - /* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */ | ||
| 91 | - | ||
| 92 | - /*- | ||
| 93 | - * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> | ||
| 94 | - * | ||
| 95 | - * Permission to use, copy, modify, and distribute this software for any | ||
| 96 | - * purpose with or without fee is hereby granted, provided that the above | ||
| 97 | - * copyright notice and this permission notice appear in all copies. | ||
| 98 | - * | ||
| 99 | - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 100 | - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 101 | - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 102 | - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 103 | - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 104 | - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 105 | - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 106 | - */ | ||
| 107 | - | ||
| 108 | - //#include <sys/cdefs.h> // **** | ||
| 109 | - //#include <cstddef> // **** | ||
| 110 | - // __FBSDID("$FreeBSD: stable/9/sys/libkern/strlcpy.c 243811 2012-12-03 18:08:44Z delphij $"); // **** | ||
| 111 | - | ||
| 112 | - // #include <sys/types.h> // **** | ||
| 113 | - // #include <sys/libkern.h> // **** | ||
| 114 | - | ||
| 115 | - /* | ||
| 116 | - * Copy src to string dst of size siz. At most siz-1 characters | ||
| 117 | - * will be copied. Always NUL terminates (unless siz == 0). | ||
| 118 | - * Returns strlen(src); if retval >= siz, truncation occurred. | ||
| 119 | - */ | ||
| 120 | - | ||
| 121 | - //#define __restrict // **** | ||
| 122 | - | ||
| 123 | - size_t strlcpy(char * __restrict dst, const char * __restrict src, size_t siz) | ||
| 124 | - { | ||
| 125 | - char *d = dst; | ||
| 126 | - const char *s = src; | ||
| 127 | - size_t n = siz; | ||
| 128 | - | ||
| 129 | - /* Copy as many bytes as will fit */ | ||
| 130 | - if (n != 0) { | ||
| 131 | - while (--n != 0) { | ||
| 132 | - if ((*d++ = *s++) == '\0') | ||
| 133 | - break; | ||
| 134 | - } | ||
| 135 | - } | ||
| 136 | - | ||
| 137 | - /* Not enough room in dst, add NUL and traverse rest of src */ | ||
| 138 | - if (n == 0) { | ||
| 139 | - if (siz != 0) | ||
| 140 | - *d = '\0'; /* NUL-terminate dst */ | ||
| 141 | - while (*s++) | ||
| 142 | - ; | ||
| 143 | - } | ||
| 144 | - | ||
| 145 | - return(s - src - 1); /* count does not include NUL */ | 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); | ||
| 146 | } | 258 | } |
| 147 | - | ||
| 148 | - // http://www.cplusplus.com/forum/general/141779///////////////////////// inet_ntop.c (modified) ////////////////////////// | 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 | +{ | ||
| 149 | /* | 271 | /* |
| 150 | - * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") | ||
| 151 | - * Copyright (c) 1996-1999 by Internet Software Consortium. | ||
| 152 | - * | ||
| 153 | - * Permission to use, copy, modify, and distribute this software for any | ||
| 154 | - * purpose with or without fee is hereby granted, provided that the above | ||
| 155 | - * copyright notice and this permission notice appear in all copies. | ||
| 156 | - * | ||
| 157 | - * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES | ||
| 158 | - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 159 | - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR | ||
| 160 | - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 161 | - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 162 | - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT | ||
| 163 | - * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 164 | - */ | ||
| 165 | - | ||
| 166 | - // #if defined(LIBC_SCCS) && !defined(lint) // **** | ||
| 167 | - //static const char rcsid[] = "$Id: inet_ntop.c,v 1.3.18.2 2005/11/03 23:02:22 marka Exp $"; | ||
| 168 | - // #endif /* LIBC_SCCS and not lint */ // **** | ||
| 169 | - // #include <sys/cdefs.h> // **** | ||
| 170 | - // __FBSDID("$FreeBSD: stable/9/sys/libkern/inet_ntop.c 213103 2010-09-24 15:01:45Z attilio $"); // **** | ||
| 171 | - | ||
| 172 | - //#define _WIN32_WINNT _WIN32_WINNT_WIN8 // **** | ||
| 173 | - //#include <Ws2tcpip.h> // **** | ||
| 174 | - //#pragma comment(lib, "Ws2_32.lib") // **** | ||
| 175 | - //#include <cstdio> // **** | ||
| 176 | - | ||
| 177 | - // #include <sys/param.h> // **** | ||
| 178 | - // #include <sys/socket.h> // **** | ||
| 179 | - // #include <sys/systm.h> // **** | ||
| 180 | - | ||
| 181 | - // #include <netinet/in.h> // **** | ||
| 182 | - | ||
| 183 | - /*% | ||
| 184 | - * WARNING: Don't even consider trying to compile this on a system where | ||
| 185 | - * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. | 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. | ||
| 186 | */ | 277 | */ |
| 187 | - | ||
| 188 | - static char *inet_ntop4(const u_char *src, char *dst, socklen_t size); | ||
| 189 | - static char *inet_ntop6(const u_char *src, char *dst, socklen_t size); | ||
| 190 | - | ||
| 191 | - /* char * | ||
| 192 | - * inet_ntop(af, src, dst, size) | ||
| 193 | - * convert a network format address to presentation format. | ||
| 194 | - * return: | ||
| 195 | - * pointer to presentation format address (`dst'), or NULL (see errno). | ||
| 196 | - * author: | ||
| 197 | - * Paul Vixie, 1996. | 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. | ||
| 198 | */ | 289 | */ |
| 199 | - const char* inet_ntop(int af, const void *src, char *dst, socklen_t size) | ||
| 200 | - { | ||
| 201 | - switch (af) { | ||
| 202 | - case AF_INET: | ||
| 203 | - return (inet_ntop4( (unsigned char*)src, (char*)dst, size)); // **** | ||
| 204 | - #ifdef AF_INET6 | ||
| 205 | - //#error "IPv6 not supported" | ||
| 206 | - //case AF_INET6: | ||
| 207 | - // return (char*)(inet_ntop6( (unsigned char*)src, (char*)dst, size)); // **** | ||
| 208 | - #endif | ||
| 209 | - default: | ||
| 210 | - // return (NULL); // **** | ||
| 211 | - return 0 ; // **** | 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 | + } | ||
| 212 | } | 309 | } |
| 213 | - /* NOTREACHED */ | ||
| 214 | } | 310 | } |
| 215 | - | ||
| 216 | - /* const char * | ||
| 217 | - * inet_ntop4(src, dst, size) | ||
| 218 | - * format an IPv4 address | ||
| 219 | - * return: | ||
| 220 | - * `dst' (as a const) | ||
| 221 | - * notes: | ||
| 222 | - * (1) uses no statics | ||
| 223 | - * (2) takes a u_char* not an in_addr as input | ||
| 224 | - * author: | ||
| 225 | - * Paul Vixie, 1996. | ||
| 226 | - */ | ||
| 227 | - static char * inet_ntop4(const u_char *src, char *dst, socklen_t size) | ||
| 228 | - { | ||
| 229 | - static const char fmt[128] = "%u.%u.%u.%u"; | ||
| 230 | - char tmp[sizeof "255.255.255.255"]; | ||
| 231 | - int l; | ||
| 232 | - | ||
| 233 | - l = snprintf(tmp, sizeof(tmp), fmt, src[0], src[1], src[2], src[3]); // **** | ||
| 234 | - if (l <= 0 || (socklen_t) l >= size) { | ||
| 235 | - return (NULL); | ||
| 236 | - } | ||
| 237 | - strlcpy(dst, tmp, size); | ||
| 238 | - return (dst); | 311 | + if (cur.base != -1) { |
| 312 | + if (best.base == -1 || cur.len > best.len) | ||
| 313 | + best = cur; | ||
| 239 | } | 314 | } |
| 240 | - | ||
| 241 | - /* const char * | ||
| 242 | - * inet_ntop6(src, dst, size) | ||
| 243 | - * convert IPv6 binary address into presentation (printable) format | ||
| 244 | - * author: | ||
| 245 | - * Paul Vixie, 1996. | ||
| 246 | - */ | ||
| 247 | - static char * inet_ntop6(const u_char *src, char *dst, socklen_t size) | ||
| 248 | - { | ||
| 249 | - /* | ||
| 250 | - * Note that int32_t and int16_t need only be "at least" large enough | ||
| 251 | - * to contain a value of the specified size. On some systems, like | ||
| 252 | - * Crays, there is no such thing as an integer variable with 16 bits. | ||
| 253 | - * Keep this in mind if you think this function should have been coded | ||
| 254 | - * to use pointer overlays. All the world's not a VAX. | ||
| 255 | - */ | ||
| 256 | - char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp; | ||
| 257 | - struct { int base, len; } best, cur; | ||
| 258 | - #define NS_IN6ADDRSZ 16 | ||
| 259 | - #define NS_INT16SZ 2 | ||
| 260 | - u_int words[NS_IN6ADDRSZ / NS_INT16SZ]; | ||
| 261 | - int i; | ||
| 262 | - | ||
| 263 | - /* | ||
| 264 | - * Preprocess: | ||
| 265 | - * Copy the input (bytewise) array into a wordwise array. | ||
| 266 | - * Find the longest run of 0x00's in src[] for :: shorthanding. | ||
| 267 | - */ | ||
| 268 | - memset(words, '\0', sizeof words); | ||
| 269 | - for (i = 0; i < NS_IN6ADDRSZ; i++) | ||
| 270 | - words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3)); | 315 | + if (best.base != -1 && best.len < 2) |
| 271 | best.base = -1; | 316 | best.base = -1; |
| 272 | - best.len = 0; | ||
| 273 | - cur.base = -1; | ||
| 274 | - cur.len = 0; | ||
| 275 | - for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { | ||
| 276 | - if (words[i] == 0) { | ||
| 277 | - if (cur.base == -1) | ||
| 278 | - cur.base = i, cur.len = 1; | ||
| 279 | - else | ||
| 280 | - cur.len++; | ||
| 281 | - } else { | ||
| 282 | - if (cur.base != -1) { | ||
| 283 | - if (best.base == -1 || cur.len > best.len) | ||
| 284 | - best = cur; | ||
| 285 | - cur.base = -1; | ||
| 286 | - } | ||
| 287 | - } | ||
| 288 | - } | ||
| 289 | - if (cur.base != -1) { | ||
| 290 | - if (best.base == -1 || cur.len > best.len) | ||
| 291 | - best = cur; | ||
| 292 | - } | ||
| 293 | - if (best.base != -1 && best.len < 2) | ||
| 294 | - best.base = -1; | ||
| 295 | - | ||
| 296 | - /* | ||
| 297 | - * Format the result. | ||
| 298 | - */ | ||
| 299 | - tp = tmp; | ||
| 300 | - for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { | ||
| 301 | - /* Are we inside the best run of 0x00's? */ | ||
| 302 | - if (best.base != -1 && i >= best.base && | ||
| 303 | - i < (best.base + best.len)) { | ||
| 304 | - if (i == best.base) | ||
| 305 | - *tp++ = ':'; | ||
| 306 | - continue; | ||
| 307 | - } | ||
| 308 | - /* Are we following an initial run of 0x00s or any real hex? */ | ||
| 309 | - if (i != 0) | 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) | ||
| 310 | *tp++ = ':'; | 327 | *tp++ = ':'; |
| 311 | - /* Is this address an encapsulated IPv4? */ | ||
| 312 | - if (i == 6 && best.base == 0 && (best.len == 6 || | ||
| 313 | - (best.len == 7 && words[7] != 0x0001) || | ||
| 314 | - (best.len == 5 && words[5] == 0xffff))) { | ||
| 315 | - if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp))) | ||
| 316 | - return (NULL); | ||
| 317 | - tp += strlen(tp); | ||
| 318 | - break; | ||
| 319 | - } | ||
| 320 | - tp += sprintf(tp, "%x", words[i]); // **** | 328 | + continue; |
| 321 | } | 329 | } |
| 322 | - /* Was it a trailing run of 0x00's? */ | ||
| 323 | - if (best.base != -1 && (best.base + best.len) == | ||
| 324 | - (NS_IN6ADDRSZ / NS_INT16SZ)) | 330 | + /* Are we following an initial run of 0x00s or any real hex? */ |
| 331 | + if (i != 0) | ||
| 325 | *tp++ = ':'; | 332 | *tp++ = ':'; |
| 326 | - *tp++ = '\0'; | ||
| 327 | - | ||
| 328 | - /* | ||
| 329 | - * Check for overflow, copy, and we're done. | ||
| 330 | - */ | ||
| 331 | - if ((socklen_t)(tp - tmp) > size) { | ||
| 332 | - return (NULL); | 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; | ||
| 333 | } | 341 | } |
| 334 | - strcpy(dst, tmp); | ||
| 335 | - return (dst); | 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); | ||
| 336 | } | 355 | } |
| 356 | + strcpy(dst, tmp); | ||
| 357 | + return (dst); | ||
| 358 | +} | ||
| 337 | 359 | ||
| 338 | #define Set_errno(num) SetLastError((num)) | 360 | #define Set_errno(num) SetLastError((num)) |
| 339 | 361 | ||
| @@ -347,61 +369,5 @@ int socket_cleanup() | @@ -347,61 +369,5 @@ int socket_cleanup() | ||
| 347 | /* from public\sdk\inc\crt\errno.h */ | 369 | /* from public\sdk\inc\crt\errno.h */ |
| 348 | #define ENOSPC 28 | 370 | #define ENOSPC 28 |
| 349 | 371 | ||
| 350 | -/* | ||
| 351 | - * | ||
| 352 | - */ | ||
| 353 | -/* | ||
| 354 | -#ifndef INET_ADDRSTRLEN | ||
| 355 | -#define INET_ADDRSTRLEN 16 | ||
| 356 | -#endif | ||
| 357 | - | ||
| 358 | -static const char * | ||
| 359 | -inet_ntop_v4 (const void *src, char *dst, size_t size) | ||
| 360 | -{ | ||
| 361 | - const char digits[] = "0123456789"; | ||
| 362 | - int i; | ||
| 363 | - struct in_addr *addr = (struct in_addr *)src; | ||
| 364 | - u_long a = ntohl(addr->s_addr); | ||
| 365 | - const char *orig_dst = dst; | ||
| 366 | - | ||
| 367 | - if (size < INET_ADDRSTRLEN) { | ||
| 368 | - Set_errno(ENOSPC); | ||
| 369 | - return NULL; | ||
| 370 | - } | ||
| 371 | - for (i = 0; i < 4; ++i) { | ||
| 372 | - int n = (a >> (24 - i * 8)) & 0xFF; | ||
| 373 | - int non_zerop = 0; | ||
| 374 | - | ||
| 375 | - if (non_zerop || n / 100 > 0) { | ||
| 376 | - *dst++ = digits[n / 100]; | ||
| 377 | - n %= 100; | ||
| 378 | - non_zerop = 1; | ||
| 379 | - } | ||
| 380 | - if (non_zerop || n / 10 > 0) { | ||
| 381 | - *dst++ = digits[n / 10]; | ||
| 382 | - n %= 10; | ||
| 383 | - non_zerop = 1; | ||
| 384 | - } | ||
| 385 | - *dst++ = digits[n]; | ||
| 386 | - if (i != 3) | ||
| 387 | - *dst++ = '.'; | ||
| 388 | - } | ||
| 389 | - *dst++ = '\0'; | ||
| 390 | - return orig_dst; | ||
| 391 | -} | ||
| 392 | - | ||
| 393 | -const char * | ||
| 394 | -inet_ntop(int af, const void *src, char *dst, size_t size) | ||
| 395 | -{ | ||
| 396 | - switch (af) { | ||
| 397 | - case AF_INET : | ||
| 398 | - return inet_ntop_v4 (src, dst, size); | ||
| 399 | - default : | ||
| 400 | - Set_errno(EAFNOSUPPORT); | ||
| 401 | - return NULL; | ||
| 402 | - } | ||
| 403 | -} | ||
| 404 | - | ||
| 405 | -*/ | ||
| 406 | #endif | 372 | #endif |
| 407 | 373 |
| 1 | #ifndef SRS_WIN_PORTING_H | 1 | #ifndef SRS_WIN_PORTING_H |
| 2 | #define SRS_WIN_PORTING_H | 2 | #define SRS_WIN_PORTING_H |
| 3 | 3 | ||
| 4 | -#if !defined(_WIN32) || defined(__CYGWIN__) /*not on windows or it's cygwin. _WIN32 includes both 32-bit and 64-bit*/ | ||
| 5 | - | ||
| 6 | -#define SOCKET_ETIME ETIME | ||
| 7 | -#define SOCKET_ECONNRESET ECONNRESET | 4 | +// for srs-librtmp, @see https://github.com/winlinvip/simple-rtmp-server/issues/213 |
| 5 | +#if defined(_WIN32) | ||
| 6 | + #include <windows.h> | ||
| 7 | +#endif | ||
| 8 | 8 | ||
| 9 | -#define SOCKET int | ||
| 10 | -#define SOCKET_ERRNO() errno | ||
| 11 | -#define SOCKET_RESET(x) x=-1 | ||
| 12 | -#define SOCKET_CLOSE(x) if(x>=0){::close(x);x=-1;} | ||
| 13 | -#define SOCKET_VALID(x) (x>=0) | ||
| 14 | -#define SOCKET_SETUP() {} | ||
| 15 | -#define SOCKET_CLEANUP() {} | 9 | +/** |
| 10 | +* for linux like, | ||
| 11 | +* for example, not on windows or it's cygwin. | ||
| 12 | +* while the _WIN32 includes both 32-bit and 64-bit | ||
| 13 | +*/ | ||
| 14 | +#if !defined(_WIN32) || defined(__CYGWIN__) | ||
| 15 | + #define SOCKET_ETIME ETIME | ||
| 16 | + #define SOCKET_ECONNRESET ECONNRESET | ||
| 16 | 17 | ||
| 18 | + #define SOCKET int | ||
| 19 | + #define SOCKET_ERRNO() errno | ||
| 20 | + #define SOCKET_RESET(fd) fd = -1; (void)0 | ||
| 21 | + #define SOCKET_CLOSE(fd) \ | ||
| 22 | + if (fd > 0) {\ | ||
| 23 | + ::close(fd); \ | ||
| 24 | + fd = -1; \ | ||
| 25 | + } \ | ||
| 26 | + (void)0 | ||
| 27 | + #define SOCKET_VALID(x) (x > 0) | ||
| 28 | + #define SOCKET_SETUP() (void)0 | ||
| 29 | + #define SOCKET_CLEANUP() (void)0 | ||
| 17 | #else /*on windows, but not on cygwin*/ | 30 | #else /*on windows, but not on cygwin*/ |
| 31 | + #include <sys/stat.h> | ||
| 32 | + #include <time.h> | ||
| 33 | + #include <winsock2.h> | ||
| 34 | + #include <stdint.h> | ||
| 18 | 35 | ||
| 19 | -#include <sys/stat.h> | ||
| 20 | -#include <time.h> | ||
| 21 | -#include <winsock2.h> | ||
| 22 | -#include <stdint.h> | 36 | + #ifdef _MSC_VER //for VS2010 |
| 37 | + #include <io.h> | ||
| 38 | + #include <fcntl.h> | ||
| 39 | + #define S_IRUSR _S_IREAD | ||
| 40 | + #define S_IWUSR _S_IWRITE | ||
| 41 | + #define open _open | ||
| 42 | + #define close _close | ||
| 43 | + #define lseek _lseek | ||
| 44 | + #define write _write | ||
| 45 | + #define read _read | ||
| 23 | 46 | ||
| 24 | -#ifdef _MSC_VER //for VS2010 | ||
| 25 | -#include <io.h> | ||
| 26 | -#include <fcntl.h> | ||
| 27 | -#define S_IRUSR _S_IREAD | ||
| 28 | -#define S_IWUSR _S_IWRITE | ||
| 29 | -#define open _open | ||
| 30 | -#define close _close | ||
| 31 | -#define lseek _lseek | ||
| 32 | -#define write _write | ||
| 33 | -#define read _read | ||
| 34 | - | ||
| 35 | -typedef int ssize_t; | ||
| 36 | -typedef int pid_t; | ||
| 37 | -typedef int mode_t; | ||
| 38 | -typedef int64_t useconds_t; | ||
| 39 | -#endif | 47 | + typedef int ssize_t; |
| 48 | + typedef int pid_t; | ||
| 49 | + typedef int mode_t; | ||
| 50 | + typedef int64_t useconds_t; | ||
| 51 | + #endif | ||
| 40 | 52 | ||
| 41 | -#define S_IRGRP 0 | ||
| 42 | -#define S_IWGRP 0 | ||
| 43 | -#define S_IXGRP 0 | ||
| 44 | -#define S_IRWXG 0 | ||
| 45 | -#define S_IROTH 0 | ||
| 46 | -#define S_IWOTH 0 | ||
| 47 | -#define S_IXOTH 0 | ||
| 48 | -#define S_IRWXO 0 | 53 | + #define S_IRGRP 0 |
| 54 | + #define S_IWGRP 0 | ||
| 55 | + #define S_IXGRP 0 | ||
| 56 | + #define S_IRWXG 0 | ||
| 57 | + #define S_IROTH 0 | ||
| 58 | + #define S_IWOTH 0 | ||
| 59 | + #define S_IXOTH 0 | ||
| 60 | + #define S_IRWXO 0 | ||
| 49 | 61 | ||
| 50 | -#define PRId64 "lld" | 62 | + #define PRId64 "lld" |
| 51 | 63 | ||
| 52 | -#define SOCKET_ETIME WSAETIMEDOUT | ||
| 53 | -#define SOCKET_ECONNRESET WSAECONNRESET | ||
| 54 | -#define SOCKET_ERRNO() WSAGetLastError() | ||
| 55 | -#define SOCKET_RESET(x) x=INVALID_SOCKET | ||
| 56 | -#define SOCKET_CLOSE(x) if(x!=INVALID_SOCKET){::closesocket(x);x=INVALID_SOCKET;} | ||
| 57 | -#define SOCKET_VALID(x) (x!=INVALID_SOCKET) | ||
| 58 | -#define SOCKET_BUFF(x) ((char*)x) | ||
| 59 | -#define SOCKET_SETUP() socket_setup() | ||
| 60 | -#define SOCKET_CLEANUP() socket_cleanup() | 64 | + #define SOCKET_ETIME WSAETIMEDOUT |
| 65 | + #define SOCKET_ECONNRESET WSAECONNRESET | ||
| 66 | + #define SOCKET_ERRNO() WSAGetLastError() | ||
| 67 | + #define SOCKET_RESET(x) x=INVALID_SOCKET | ||
| 68 | + #define SOCKET_CLOSE(x) if(x!=INVALID_SOCKET){::closesocket(x);x=INVALID_SOCKET;} | ||
| 69 | + #define SOCKET_VALID(x) (x!=INVALID_SOCKET) | ||
| 70 | + #define SOCKET_BUFF(x) ((char*)x) | ||
| 71 | + #define SOCKET_SETUP() socket_setup() | ||
| 72 | + #define SOCKET_CLEANUP() socket_cleanup() | ||
| 61 | 73 | ||
| 62 | -typedef uint32_t u_int32_t; | ||
| 63 | -typedef uint8_t u_int8_t; | ||
| 64 | -typedef int socklen_t; | ||
| 65 | -struct iovec { | ||
| 66 | - void* iov_base; /* Starting address */ | ||
| 67 | - size_t iov_len; /* Length in bytes */ | ||
| 68 | -}; | 74 | + typedef uint32_t u_int32_t; |
| 75 | + typedef uint8_t u_int8_t; | ||
| 76 | + typedef int socklen_t; | ||
| 77 | + struct iovec { | ||
| 78 | + void* iov_base; /* Starting address */ | ||
| 79 | + size_t iov_len; /* Length in bytes */ | ||
| 80 | + }; | ||
| 69 | 81 | ||
| 70 | -#define snprintf _snprintf | ||
| 71 | -ssize_t writev(int fd, const struct iovec *iov, int iovcnt); | ||
| 72 | -const char* inet_ntop(int af, const void *src, char *dst, socklen_t size); | ||
| 73 | -int gettimeofday(struct timeval* tv, struct timezone* tz); | ||
| 74 | -pid_t getpid(void); | ||
| 75 | -int usleep(useconds_t usec); | ||
| 76 | -int socket_setup(); | ||
| 77 | -int socket_cleanup(); | 82 | + #define snprintf _snprintf |
| 83 | + ssize_t writev(int fd, const struct iovec *iov, int iovcnt); | ||
| 84 | + const char* inet_ntop(int af, const void *src, char *dst, socklen_t size); | ||
| 85 | + int gettimeofday(struct timeval* tv, struct timezone* tz); | ||
| 86 | + pid_t getpid(void); | ||
| 87 | + int usleep(useconds_t usec); | ||
| 88 | + int socket_setup(); | ||
| 89 | + int socket_cleanup(); | ||
| 78 | #endif | 90 | #endif |
| 79 | 91 | ||
| 80 | #endif //SRS_WIN_PORTING_H | 92 | #endif //SRS_WIN_PORTING_H |
| @@ -30,11 +30,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -30,11 +30,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 30 | 30 | ||
| 31 | #include <srs_core.hpp> | 31 | #include <srs_core.hpp> |
| 32 | 32 | ||
| 33 | -// success, ok | ||
| 34 | -#if !defined(_WIN32) || defined(__CYGWIN__) //avoid redefine error on Windows | 33 | +// for srs-librtmp, @see https://github.com/winlinvip/simple-rtmp-server/issues/213 |
| 34 | +#ifndef _WIN32 | ||
| 35 | #define ERROR_SUCCESS 0 | 35 | #define ERROR_SUCCESS 0 |
| 36 | -#else | ||
| 37 | -#include <windows.h> | ||
| 38 | #endif | 36 | #endif |
| 39 | 37 | ||
| 40 | /////////////////////////////////////////////////////// | 38 | /////////////////////////////////////////////////////// |
| @@ -45,28 +45,22 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -45,28 +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 | - //fd = -1; | ||
| 49 | - SOCKET_RESET(fd); | 48 | + SOCKET_RESET(fd); |
| 50 | send_timeout = recv_timeout = ST_UTIME_NO_TIMEOUT; | 49 | send_timeout = recv_timeout = ST_UTIME_NO_TIMEOUT; |
| 51 | recv_bytes = send_bytes = 0; | 50 | recv_bytes = send_bytes = 0; |
| 52 | - SOCKET_SETUP(); | 51 | + SOCKET_SETUP(); |
| 53 | } | 52 | } |
| 54 | 53 | ||
| 55 | SimpleSocketStream::~SimpleSocketStream() | 54 | SimpleSocketStream::~SimpleSocketStream() |
| 56 | { | 55 | { |
| 57 | - //if (fd != -1) { | ||
| 58 | - // ::close(fd); | ||
| 59 | - // fd = -1; | ||
| 60 | - //} | ||
| 61 | - SOCKET_CLOSE(fd); | ||
| 62 | - SOCKET_CLEANUP(); | 56 | + SOCKET_CLOSE(fd); |
| 57 | + SOCKET_CLEANUP(); | ||
| 63 | } | 58 | } |
| 64 | 59 | ||
| 65 | int SimpleSocketStream::create_socket() | 60 | int SimpleSocketStream::create_socket() |
| 66 | { | 61 | { |
| 67 | - //if((fd = ::socket(AF_INET, SOCK_STREAM, 0)) < 0){ | ||
| 68 | - fd = ::socket(AF_INET, SOCK_STREAM, 0); | ||
| 69 | - if(!SOCKET_VALID(fd)){ | 62 | + fd = ::socket(AF_INET, SOCK_STREAM, 0); |
| 63 | + if (!SOCKET_VALID(fd)) { | ||
| 70 | return ERROR_SOCKET_CREATE; | 64 | return ERROR_SOCKET_CREATE; |
| 71 | } | 65 | } |
| 72 | 66 |
| @@ -22,7 +22,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -22,7 +22,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 22 | */ | 22 | */ |
| 23 | 23 | ||
| 24 | #include <srs_librtmp.hpp> | 24 | #include <srs_librtmp.hpp> |
| 25 | -#include <srs_platform.hpp> | 25 | + |
| 26 | #include <stdlib.h> | 26 | #include <stdlib.h> |
| 27 | 27 | ||
| 28 | // for srs-librtmp, @see https://github.com/winlinvip/simple-rtmp-server/issues/213 | 28 | // for srs-librtmp, @see https://github.com/winlinvip/simple-rtmp-server/issues/213 |
| @@ -34,6 +34,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -34,6 +34,7 @@ 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> | ||
| 37 | #include <srs_kernel_error.hpp> | 38 | #include <srs_kernel_error.hpp> |
| 38 | #include <srs_protocol_rtmp.hpp> | 39 | #include <srs_protocol_rtmp.hpp> |
| 39 | #include <srs_lib_simple_socket.hpp> | 40 | #include <srs_lib_simple_socket.hpp> |
| @@ -107,56 +108,6 @@ struct Context | @@ -107,56 +108,6 @@ struct Context | ||
| 107 | } | 108 | } |
| 108 | }; | 109 | }; |
| 109 | 110 | ||
| 110 | -// for srs-librtmp, @see https://github.com/winlinvip/simple-rtmp-server/issues/213 | ||
| 111 | -#ifdef _WIN32 | ||
| 112 | - | ||
| 113 | -/* | ||
| 114 | - int open(const char *pathname, int flags) | ||
| 115 | - { | ||
| 116 | - return open(pathname, flags, 0); | ||
| 117 | - } | ||
| 118 | - | ||
| 119 | - int open(const char *pathname, int flags, mode_t mode) | ||
| 120 | - { | ||
| 121 | - FILE* file = NULL; | ||
| 122 | - | ||
| 123 | - if ((flags & O_RDONLY) == O_RDONLY) { | ||
| 124 | - file = fopen(pathname, "r"); | ||
| 125 | - } else { | ||
| 126 | - file = fopen(pathname, "w+"); | ||
| 127 | - } | ||
| 128 | - | ||
| 129 | - if (file == NULL) { | ||
| 130 | - return -1; | ||
| 131 | - } | ||
| 132 | - | ||
| 133 | - return (int)file; | ||
| 134 | - } | ||
| 135 | - | ||
| 136 | - int close(int fd) | ||
| 137 | - { | ||
| 138 | - FILE* file = (FILE*)fd; | ||
| 139 | - return fclose(file); | ||
| 140 | - } | ||
| 141 | - | ||
| 142 | - off_t lseek(int fd, off_t offset, int whence) | ||
| 143 | - { | ||
| 144 | - return (off_t)fseek((FILE*)fd, offset, whence); | ||
| 145 | - } | ||
| 146 | - | ||
| 147 | - ssize_t write(int fd, const void *buf, size_t count) | ||
| 148 | - { | ||
| 149 | - return (ssize_t)fwrite(buf, count, 1, (FILE*)fd); | ||
| 150 | - } | ||
| 151 | - | ||
| 152 | - ssize_t read(int fd, void *buf, size_t count) | ||
| 153 | - { | ||
| 154 | - return (ssize_t)fread(buf, count, 1, (FILE*)fd); | ||
| 155 | - } | ||
| 156 | -*/ | ||
| 157 | - | ||
| 158 | -#endif | ||
| 159 | - | ||
| 160 | int srs_librtmp_context_parse_uri(Context* context) | 111 | int srs_librtmp_context_parse_uri(Context* context) |
| 161 | { | 112 | { |
| 162 | int ret = ERROR_SUCCESS; | 113 | int ret = ERROR_SUCCESS; |
| @@ -31,53 +31,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -31,53 +31,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 31 | #include <sys/types.h> | 31 | #include <sys/types.h> |
| 32 | 32 | ||
| 33 | 33 | ||
| 34 | -// for srs-librtmp, @see https://github.com/winlinvip/simple-rtmp-server/issues/213 | ||
| 35 | -#if 0 | ||
| 36 | - #define _CRT_SECURE_NO_WARNINGS | ||
| 37 | - typedef unsigned long long u_int64_t; | ||
| 38 | - typedef long long int64_t; | ||
| 39 | - typedef unsigned int u_int32_t; | ||
| 40 | - typedef int int32_t; | ||
| 41 | - typedef unsigned char u_int8_t; | ||
| 42 | - typedef char int8_t; | ||
| 43 | - typedef unsigned short u_int16_t; | ||
| 44 | - typedef short int16_t; | ||
| 45 | - typedef int64_t ssize_t; | ||
| 46 | - struct iovec { | ||
| 47 | - void *iov_base; /* Starting address */ | ||
| 48 | - size_t iov_len; /* Number of bytes to transfer */ | ||
| 49 | - }; | ||
| 50 | - #include <time.h> | ||
| 51 | - #include <windows.h> | ||
| 52 | - int gettimeofday(struct timeval* tv, struct timezone* tz); | ||
| 53 | - #define PRId64 "lld" | ||
| 54 | - typedef int socklen_t; | ||
| 55 | - const char *inet_ntop(int af, const void *src, char *dst, socklen_t size); | ||
| 56 | - typedef int mode_t; | ||
| 57 | - #define S_IRUSR 0 | ||
| 58 | - #define S_IWUSR 0 | ||
| 59 | - #define S_IRGRP 0 | ||
| 60 | - #define S_IWGRP 0 | ||
| 61 | - #define S_IROTH 0 | ||
| 62 | - int open(const char *pathname, int flags); | ||
| 63 | - int open(const char *pathname, int flags, mode_t mode); | ||
| 64 | - int close(int fd); | ||
| 65 | - off_t lseek(int fd, off_t offset, int whence); | ||
| 66 | - ssize_t write(int fd, const void *buf, size_t count); | ||
| 67 | - ssize_t read(int fd, void *buf, size_t count); | ||
| 68 | - typedef int pid_t; | ||
| 69 | - pid_t getpid(void); | ||
| 70 | - #define snprintf _snprintf | ||
| 71 | - ssize_t writev(int fd, const struct iovec *iov, int iovcnt); | ||
| 72 | - typedef int64_t useconds_t; | ||
| 73 | - int usleep(useconds_t usec); | ||
| 74 | -#endif | ||
| 75 | - | ||
| 76 | -#if defined(_WIN32) && !defined(__CYGWIN__) | ||
| 77 | -#include <stdint.h> | ||
| 78 | -typedef uint32_t u_int32_t; | ||
| 79 | -#endif | ||
| 80 | - | ||
| 81 | /** | 34 | /** |
| 82 | * srs-librtmp is a librtmp like library, | 35 | * srs-librtmp is a librtmp like library, |
| 83 | * used to play/publish rtmp stream from/to rtmp server. | 36 | * used to play/publish rtmp stream from/to rtmp server. |
| @@ -19,7 +19,7 @@ | @@ -19,7 +19,7 @@ | ||
| 19 | #undef SRS_AUTO_HTTP_CALLBACK | 19 | #undef SRS_AUTO_HTTP_CALLBACK |
| 20 | #undef SRS_AUTO_SSL | 20 | #undef SRS_AUTO_SSL |
| 21 | #undef SRS_AUTO_FFMPEG_TOOL | 21 | #undef SRS_AUTO_FFMPEG_TOOL |
| 22 | -#define SRS_AUTO_FFMPEG_STUB | 22 | +#undef SRS_AUTO_FFMPEG_STUB |
| 23 | #undef SRS_AUTO_TRANSCODE | 23 | #undef SRS_AUTO_TRANSCODE |
| 24 | #undef SRS_AUTO_INGEST | 24 | #undef SRS_AUTO_INGEST |
| 25 | #undef SRS_AUTO_STAT | 25 | #undef SRS_AUTO_STAT |
| @@ -77,9 +77,9 @@ | @@ -77,9 +77,9 @@ | ||
| 77 | </Link> | 77 | </Link> |
| 78 | </ItemDefinitionGroup> | 78 | </ItemDefinitionGroup> |
| 79 | <ItemGroup> | 79 | <ItemGroup> |
| 80 | - <ClCompile Include="..\research\librtmp\srs_play.c" /> | 80 | + <ClCompile Include="srs_play.c" /> |
| 81 | </ItemGroup> | 81 | </ItemGroup> |
| 82 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | 82 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> |
| 83 | <ImportGroup Label="ExtensionTargets"> | 83 | <ImportGroup Label="ExtensionTargets"> |
| 84 | </ImportGroup> | 84 | </ImportGroup> |
| 85 | -</Project> | ||
| 85 | +</Project> |
| @@ -15,8 +15,8 @@ | @@ -15,8 +15,8 @@ | ||
| 15 | </Filter> | 15 | </Filter> |
| 16 | </ItemGroup> | 16 | </ItemGroup> |
| 17 | <ItemGroup> | 17 | <ItemGroup> |
| 18 | - <ClCompile Include="..\research\librtmp\srs_play.c"> | 18 | + <ClCompile Include="srs_play.c"> |
| 19 | <Filter>Source Files</Filter> | 19 | <Filter>Source Files</Filter> |
| 20 | </ClCompile> | 20 | </ClCompile> |
| 21 | </ItemGroup> | 21 | </ItemGroup> |
| 22 | -</Project> | ||
| 22 | +</Project> |
-
请 注册 或 登录 后发表评论