winlin

merge from allspace srs-librtmp for win vs2010. 2.0.36

... ... @@ -112,7 +112,7 @@ int main(int argc, char** argv)
printf("version: %d.%d.%d\n", srs_version_major(), srs_version_minor(), srs_version_revision());
rtmp = srs_rtmp_create("rtmp://ossrs.net/live/livestream");
srs_lib_trace("create rtmp success");
srs_human_trace("create rtmp success");
srs_rtmp_destroy(rtmp);
return 0;
... ...
... ... @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// current release version
#define VERSION_MAJOR 2
#define VERSION_MINOR 0
#define VERSION_REVISION 35
#define VERSION_REVISION 36
// server info.
#define RTMP_SIG_SRS_KEY "SRS"
#define RTMP_SIG_SRS_ROLE "origin/edge server"
... ...
... ... @@ -45,22 +45,22 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
SimpleSocketStream::SimpleSocketStream()
{
fd = -1;
SOCKET_RESET(fd);
send_timeout = recv_timeout = ST_UTIME_NO_TIMEOUT;
recv_bytes = send_bytes = 0;
SOCKET_SETUP();
}
SimpleSocketStream::~SimpleSocketStream()
{
if (fd != -1) {
::close(fd);
fd = -1;
}
SOCKET_CLOSE(fd);
SOCKET_CLEANUP();
}
int SimpleSocketStream::create_socket()
{
if((fd = ::socket(AF_INET, SOCK_STREAM, 0)) < 0){
fd = ::socket(AF_INET, SOCK_STREAM, 0);
if (!SOCKET_VALID(fd)) {
return ERROR_SOCKET_CREATE;
}
... ... @@ -95,12 +95,12 @@ int SimpleSocketStream::read(void* buf, size_t size, ssize_t* nread)
// On success a non-negative integer indicating the number of bytes actually read is returned
// (a value of 0 means the network connection is closed or end of file is reached).
if (nb_read <= 0) {
if (nb_read < 0 && errno == ETIME) {
if (nb_read < 0 && SOCKET_ERRNO() == SOCKET_ETIME) {
return ERROR_SOCKET_TIMEOUT;
}
if (nb_read == 0) {
errno = ECONNRESET;
errno = SOCKET_ECONNRESET;
}
return ERROR_SOCKET_READ;
... ... @@ -158,7 +158,7 @@ int SimpleSocketStream::writev(const iovec *iov, int iov_size, ssize_t* nwrite)
// returned, and errno is set appropriately.
if (nb_write <= 0) {
// @see https://github.com/winlinvip/simple-rtmp-server/issues/200
if (nb_write < 0 && errno == ETIME) {
if (nb_write < 0 && SOCKET_ERRNO() == SOCKET_ETIME) {
return ERROR_SOCKET_TIMEOUT;
}
... ... @@ -215,7 +215,7 @@ int SimpleSocketStream::write(void* buf, size_t size, ssize_t* nwrite)
if (nb_write <= 0) {
// @see https://github.com/winlinvip/simple-rtmp-server/issues/200
if (nb_write < 0 && errno == ETIME) {
if (nb_write < 0 && SOCKET_ERRNO() == SOCKET_ETIME) {
return ERROR_SOCKET_TIMEOUT;
}
... ...
... ... @@ -31,6 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_core.hpp>
#include <srs_protocol_io.hpp>
#include <srs_librtmp.hpp>
/**
* simple socket stream,
... ... @@ -43,7 +44,7 @@ private:
int64_t send_timeout;
int64_t recv_bytes;
int64_t send_bytes;
int fd;
SOCKET fd;
public:
SimpleSocketStream();
virtual ~SimpleSocketStream();
... ...
... ... @@ -133,47 +133,29 @@ struct Context
return 0;
}
int open(const char *pathname, int flags)
int socket_setup()
{
return open(pathname, flags, 0);
}
int open(const char *pathname, int flags, mode_t mode)
{
FILE* file = NULL;
if ((flags & O_RDONLY) == O_RDONLY) {
file = fopen(pathname, "r");
} else {
file = fopen(pathname, "w+");
}
if (file == NULL) {
WORD wVersionRequested;
WSADATA wsaData;
int err;
/* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */
wVersionRequested = MAKEWORD(2, 2);
err = WSAStartup(wVersionRequested, &wsaData);
if (err != 0) {
/* Tell the user that we could not find a usable */
/* Winsock DLL. */
//printf("WSAStartup failed with error: %d\n", err);
return -1;
}
return (int)file;
}
int close(int fd)
{
FILE* file = (FILE*)fd;
return fclose(file);
}
off_t lseek(int fd, off_t offset, int whence)
{
return (off_t)fseek((FILE*)fd, offset, whence);
}
ssize_t write(int fd, const void *buf, size_t count)
{
return (ssize_t)fwrite(buf, count, 1, (FILE*)fd);
return 0;
}
ssize_t read(int fd, void *buf, size_t count)
int socket_cleanup()
{
return (ssize_t)fread(buf, count, 1, (FILE*)fd);
WSACleanup();
return 0;
}
pid_t getpid(void)
... ...
... ... @@ -31,7 +31,23 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <sys/types.h>
// for srs-librtmp, @see https://github.com/winlinvip/simple-rtmp-server/issues/213
#ifdef _WIN32
#ifndef _WIN32
#define SOCKET_ETIME ETIME
#define SOCKET_ECONNRESET ECONNRESET
#define SOCKET int
#define SOCKET_ERRNO() errno
#define SOCKET_RESET(fd) fd = -1; (void)0
#define SOCKET_CLOSE(fd) \
if (fd > 0) {\
::close(fd); \
fd = -1; \
} \
(void)0
#define SOCKET_VALID(x) (x > 0)
#define SOCKET_SETUP() (void)0
#define SOCKET_CLEANUP() (void)0
#else
#define _CRT_SECURE_NO_WARNINGS
typedef unsigned long long u_int64_t;
typedef long long int64_t;
... ... @@ -50,6 +66,17 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <windows.h>
int gettimeofday(struct timeval* tv, struct timezone* tz);
#define PRId64 "lld"
#define SOCKET_ETIME WSAETIMEDOUT
#define SOCKET_ECONNRESET WSAECONNRESET
#define SOCKET_ERRNO() WSAGetLastError()
#define SOCKET_RESET(x) x=INVALID_SOCKET
#define SOCKET_CLOSE(x) if(x!=INVALID_SOCKET){::closesocket(x);x=INVALID_SOCKET;}
#define SOCKET_VALID(x) (x!=INVALID_SOCKET)
#define SOCKET_BUFF(x) ((char*)x)
#define SOCKET_SETUP() socket_setup()
#define SOCKET_CLEANUP() socket_cleanup()
typedef int socklen_t;
const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);
typedef int mode_t;
... ... @@ -58,18 +85,23 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#define S_IRGRP 0
#define S_IWGRP 0
#define S_IROTH 0
int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);
int close(int fd);
off_t lseek(int fd, off_t offset, int whence);
ssize_t write(int fd, const void *buf, size_t count);
ssize_t read(int fd, void *buf, size_t count);
#include <io.h>
#include <fcntl.h>
#define open _open
#define close _close
#define lseek _lseek
#define write _write
#define read _read
typedef int pid_t;
pid_t getpid(void);
#define snprintf _snprintf
ssize_t writev(int fd, const struct iovec *iov, int iovcnt);
typedef int64_t useconds_t;
int usleep(useconds_t usec);
int socket_setup();
int socket_cleanup();
#endif
/**
... ...