Commit 658b65ad authored by dscho's avatar dscho

support MinGW32!

parent 7d3b1c97
2004-12-02 Johannes E. Schindelin <Johannes.Schindelin@gmx.de>
* make LibVNCServer compile & work on MinGW32
2004-11-30 "Leiradella, Andre V Matos Da Cunha" <ANDRE.LEIRADELLA@bra.xerox.com>
* libvncclient/sockets.c: return TRUE in every case of success
......
immediate:
----------
MinGW32 doesn't do fcntl on sockets; use setsockopt instead...
always undraw cursor after sending updates, but do not mark region as modified.
add automatic tests (plasma?)
if preferredEncoding is set outside of libvncserver, don't override it.
......
DEFINES=-I.. -g -Wall
LDADD = ../libvncclient/libvncclient.a
LDADD = ../libvncclient/libvncclient.a @WSOCKLIB@
if WITH_FFMPEG
FFMPEG_HOME=@with_ffmpeg@
......
#include <SDL/SDL.h>
#include <SDL.h>
#include <rfb/rfbclient.h>
static rfbBool resize(rfbClient* client) {
......@@ -186,6 +186,46 @@ void update(rfbClient* cl,int x,int y,int w,int h) {
SDL_UpdateRect(cl->clientData, x, y, w, h);
}
#ifdef __MINGW32__
#define LOG_TO_FILE
#endif
#ifdef LOG_TO_FILE
#include <stdarg.h>
static void
log_to_file(const char *format, ...)
{
FILE* logfile;
static char* logfile_str=0;
va_list args;
char buf[256];
time_t log_clock;
if(!rfbEnableClientLogging)
return;
if(logfile_str==0) {
logfile_str=getenv("VNCLOG");
if(logfile_str==0)
logfile_str="vnc.log";
}
logfile=fopen(logfile_str,"a");
va_start(args, format);
time(&log_clock);
strftime(buf, 255, "%d/%m/%Y %X ", localtime(&log_clock));
fprintf(logfile,buf);
vfprintf(logfile, format, args);
fflush(logfile);
va_end(args);
fclose(logfile);
}
#endif
#ifdef mac
#define main SDLmain
#endif
......@@ -195,6 +235,10 @@ int main(int argc,char** argv) {
int i,buttonMask=0;
SDL_Event e;
#ifdef LOG_TO_FILE
rfbClientLog=rfbClientErr=log_to_file;
#endif
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
cl=rfbGetClient(5,3,2);
......
......@@ -32,7 +32,6 @@ fi
AH_TEMPLATE(FFMPEG, [Use ffmpeg (for vnc2mpg)])
AC_ARG_WITH(ffmpeg,
[ --with-ffmpeg=dir set ffmpeg home directory],,)
#AM_DEFINE(FFMPEG, "$with_ffmpeg")
AC_SUBST(with_ffmpeg)
AM_CONDITIONAL(WITH_FFMPEG, test ! -z "$with_ffmpeg")
......@@ -143,6 +142,13 @@ AM_CONDITIONAL(HAVE_LIBSDL, test "x$with_sdl" = "xyes")
AC_SUBST(SDL_CFLAGS)
AC_SUBST(SDL_LIBS)
MINGW=`uname -s | grep MINGW 2>/dev/null`
AM_CONDITIONAL(MINGW, test ! -z "$MINGW" )
if test ! -z "$MINGW"; then
WSOCKLIB="-lws2_32"
fi
AC_SUBST(WSOCKLIB)
# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h sys/time.h sys/timeb.h syslog.h unistd.h])
......
DEFINES = -I ..
LDADD = ../libvncserver/libvncserver.a
LDADD = ../libvncserver/libvncserver.a @WSOCKLIB@
noinst_PROGRAMS=zippy
......
DEFINES=-I.. -g -Wall
LDADD = ../libvncserver/libvncserver.a
LDADD = ../libvncserver/libvncserver.a @WSOCKLIB@
if OSX
MAC=mac
......
......@@ -2,7 +2,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#endif
#include <rfb/rfb.h>
#include <rfb/default8x16.h>
......
......@@ -23,9 +23,13 @@
#include <unistd.h>
#include <sys/types.h>
#ifdef __MINGW32__
#include <winsock2.h>
#else
#include <sys/wait.h>
#include <sys/time.h>
#include <sys/utsname.h>
#endif
#include <sys/time.h>
#include <rfb/rfbclient.h>
/*
......@@ -36,6 +40,11 @@
void
listenForIncomingConnections(rfbClient* client)
{
#ifdef __MINGW32__
/* FIXME */
rfbClientErr("listenForIncomingConnections on MinGW32 NOT IMPLEMENTED\n");
return;
#else
int listenSocket;
fd_set fds;
......@@ -77,7 +86,7 @@ listenForIncomingConnections(rfbClient* client)
switch (fork()) {
case -1:
rfbClientErr("fork");
rfbClientErr("fork\n");
return;
case 0:
......@@ -92,6 +101,7 @@ listenForIncomingConnections(rfbClient* client)
}
}
}
#endif
}
......@@ -25,7 +25,9 @@
#include <unistd.h>
#include <errno.h>
#ifndef __MINGW32__
#include <pwd.h>
#endif
#include <rfb/rfbclient.h>
#ifdef LIBVNCSERVER_HAVE_LIBZ
#include <zlib.h>
......
......@@ -22,15 +22,23 @@
*/
#include <unistd.h>
#include <sys/socket.h>
#include <errno.h>
#include <fcntl.h>
#include <assert.h>
#include <rfb/rfbclient.h>
#ifdef WIN32
#include <winsock2.h>
#define EWOULDBLOCK WSAEWOULDBLOCK
#define close closesocket
#define read(sock,buf,len) recv(sock,buf,len,0)
#define write(sock,buf,len) send(sock,buf,len,0)
#else
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <fcntl.h>
#include <assert.h>
#include <rfb/rfbclient.h>
#endif
void PrintInHex(char *buf, int len);
......@@ -81,7 +89,12 @@ ReadFromRFBServer(rfbClient* client, char *out, unsigned int n)
diff.tv_usec+=1000000;
}
sleep (diff.tv_sec);
#ifndef __MINGW32__
/* FIXME */
usleep (diff.tv_usec);
#else
rfbClientErr("usleep on MinGW32 NOT IMPLEMENTED\n");
#endif
}
rec->tv=tv;
......@@ -114,13 +127,16 @@ ReadFromRFBServer(rfbClient* client, char *out, unsigned int n)
int i = read(client->sock, client->buf + client->buffered, RFB_BUF_SIZE - client->buffered);
if (i <= 0) {
if (i < 0) {
#ifdef WIN32
errno=WSAGetLastError();
#endif
if (errno == EWOULDBLOCK || errno == EAGAIN) {
/* TODO:
ProcessXtEvents();
*/
i = 0;
} else {
rfbClientErr("read");
rfbClientErr("read (%d: %s)\n",errno,strerror(errno));
return FALSE;
}
} else {
......@@ -143,13 +159,16 @@ ReadFromRFBServer(rfbClient* client, char *out, unsigned int n)
int i = read(client->sock, out, n);
if (i <= 0) {
if (i < 0) {
#ifdef WIN32
errno=WSAGetLastError();
#endif
if (errno == EWOULDBLOCK || errno == EAGAIN) {
/* TODO:
ProcessXtEvents();
*/
i = 0;
} else {
rfbClientErr("read");
rfbClientErr("read (%s)\n",strerror(errno));
return FALSE;
}
} else {
......@@ -200,12 +219,12 @@ WriteToRFBServer(rfbClient* client, char *buf, int n)
FD_SET(client->sock,&fds);
if (select(client->sock+1, NULL, &fds, NULL, NULL) <= 0) {
rfbClientErr("select");
rfbClientErr("select\n");
return FALSE;
}
j = 0;
} else {
rfbClientErr("write");
rfbClientErr("write\n");
return FALSE;
}
} else {
......@@ -230,25 +249,41 @@ ConnectClientToTcpAddr(unsigned int host, int port)
struct sockaddr_in addr;
int one = 1;
#ifdef WIN32
WSADATA trash;
static rfbBool WSAinitted=FALSE;
if(!WSAinitted) {
WSAinitted=TRUE;
int i=WSAStartup(MAKEWORD(2,0),&trash);
if(i!=0) {
rfbClientErr("Couldn't init Windows Sockets\n");
return -1;
}
}
#endif
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = host;
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0) {
rfbClientErr("ConnectToTcpAddr: socket");
#ifdef WIN32
errno=WSAGetLastError();
#endif
rfbClientErr("ConnectToTcpAddr: socket (%s)\n",strerror(errno));
return -1;
}
if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
rfbClientErr("ConnectToTcpAddr: connect");
rfbClientErr("ConnectToTcpAddr: connect\n");
close(sock);
return -1;
}
if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
(char *)&one, sizeof(one)) < 0) {
rfbClientErr("ConnectToTcpAddr: setsockopt");
rfbClientErr("ConnectToTcpAddr: setsockopt\n");
close(sock);
return -1;
}
......@@ -274,7 +309,7 @@ FindFreeTcpPort(void)
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0) {
rfbClientErr(": FindFreeTcpPort: socket");
rfbClientErr(": FindFreeTcpPort: socket\n");
return 0;
}
......@@ -308,25 +343,25 @@ ListenAtTcpPort(int port)
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0) {
rfbClientErr("ListenAtTcpPort: socket");
rfbClientErr("ListenAtTcpPort: socket\n");
return -1;
}
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
(const char *)&one, sizeof(one)) < 0) {
rfbClientErr("ListenAtTcpPort: setsockopt");
rfbClientErr("ListenAtTcpPort: setsockopt\n");
close(sock);
return -1;
}
if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
rfbClientErr("ListenAtTcpPort: bind");
rfbClientErr("ListenAtTcpPort: bind\n");
close(sock);
return -1;
}
if (listen(sock, 5) < 0) {
rfbClientErr("ListenAtTcpPort: listen");
rfbClientErr("ListenAtTcpPort: listen\n");
close(sock);
return -1;
}
......@@ -349,13 +384,13 @@ AcceptTcpConnection(int listenSock)
sock = accept(listenSock, (struct sockaddr *) &addr, &addrlen);
if (sock < 0) {
rfbClientErr("AcceptTcpConnection: accept");
rfbClientErr("AcceptTcpConnection: accept\n");
return -1;
}
if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
(char *)&one, sizeof(one)) < 0) {
rfbClientErr("AcceptTcpConnection: setsockopt");
rfbClientErr("AcceptTcpConnection: setsockopt\n");
close(sock);
return -1;
}
......@@ -371,10 +406,14 @@ AcceptTcpConnection(int listenSock)
rfbBool
SetNonBlocking(int sock)
{
#ifndef __MINGW32__
if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0) {
rfbClientErr("AcceptTcpConnection: fcntl");
rfbClientErr("AcceptTcpConnection: fcntl\n");
return FALSE;
}
#else
rfbClientErr("O_NONBLOCK on MinGW32 NOT IMPLEMENTED\n");
#endif
return TRUE;
}
......
......@@ -37,9 +37,18 @@ static void DummyRect(rfbClient* client, int x, int y, int w, int h) {
static char* NoPassword(rfbClient* client) {
return strdup("");
}
#ifndef __MINGW32__
#include <stdio.h>
#include <termios.h>
#endif
static char* ReadPassword(rfbClient* client) {
#ifdef __MINGW32__
/* FIXME */
rfbClientErr("ReadPassword on MinGW32 NOT IMPLEMENTED\n");
return NoPassword(client);
#else
int i;
char* p=malloc(9);
struct termios save,noecho;
......@@ -61,6 +70,7 @@ static char* ReadPassword(rfbClient* client) {
}
tcsetattr(fileno(stdin),TCSAFLUSH,&save);
return p;
#endif
}
static rfbBool MallocFrameBuffer(rfbClient* client) {
if(client->frameBuffer)
......@@ -196,7 +206,8 @@ rfbBool rfbInitClient(rfbClient* client,int* argc,char** argv) {
char* colon=strchr(argv[i],':');
if(colon) {
client->serverHost=strndup(argv[i],(int)(colon-argv[i]));
client->serverHost=strdup(argv[i]);
client->serverHost[(int)(colon-argv[i])]='\0';
client->serverPort=atoi(colon+1);
} else {
client->serverHost=strdup(argv[i]);
......
......@@ -60,7 +60,7 @@ while test $# -gt 0; do
else
libdirs="-L$libdir"
fi
echo "$libdirs" -lvncserver @LIBS@
echo "$libdirs" -lvncserver @LIBS@ @WSOCKLIB@
;;
--link)
echo @CC@
......
......@@ -161,6 +161,9 @@ rfbHttpCheckFds(rfbScreenInfoPtr rfbScreen)
rfbLogPerror("httpCheckFds: accept");
return;
}
#ifdef __MINGW32__
rfbErr("O_NONBLOCK on MinGW32 NOT IMPLEMENTED");
#else
#ifdef USE_LIBWRAP
if(!hosts_ctl("vnc",STRING_UNKNOWN,inet_ntoa(addr.sin_addr),
STRING_UNKNOWN)) {
......@@ -176,6 +179,7 @@ rfbHttpCheckFds(rfbScreenInfoPtr rfbScreen)
rfbScreen->httpSock = -1;
return;
}
flags=fcntl(rfbScreen->httpSock,F_GETFL);
if(flags==-1 ||
fcntl(rfbScreen->httpSock,F_SETFL,flags|O_NONBLOCK)==-1) {
......@@ -184,6 +188,7 @@ rfbHttpCheckFds(rfbScreenInfoPtr rfbScreen)
rfbScreen->httpSock=-1;
return;
}
#endif
/*AddEnabledDevice(httpSock);*/
}
......
......@@ -762,8 +762,10 @@ void rfbInitServer(rfbScreenInfoPtr screen)
#endif
rfbInitSockets(screen);
rfbHttpInitSockets(screen);
#ifndef __MINGW32__
if(screen->ignoreSIGPIPE)
signal(SIGPIPE,SIG_IGN);
#endif
}
#ifndef LIBVNCSERVER_HAVE_GETTIMEOFDAY
......
......@@ -45,14 +45,6 @@
#include <sys/types.h>
#endif
#ifdef WIN32
#pragma warning (disable: 4018 4761)
#define close closesocket
#define read(sock,buf,len) recv(sock,buf,len,0)
#define EWOULDBLOCK WSAEWOULDBLOCK
#define ETIMEDOUT WSAETIMEDOUT
#define write(sock,buf,len) send(sock,buf,len,0)
#else
#ifdef LIBVNCSERVER_HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
......@@ -68,7 +60,6 @@
#ifdef LIBVNCSERVER_HAVE_UNISTD_H
#include <unistd.h>
#endif
#endif
#if defined(__linux__) && defined(NEED_TIMEVAL)
struct timeval
......@@ -91,10 +82,14 @@ int allow_severity=LOG_INFO;
int deny_severity=LOG_WARNING;
#endif
/*#ifndef WIN32
int max(int i,int j) { return(i<j?j:i); }
#if defined(WIN32)
#pragma warning (disable: 4018 4761)
#define close closesocket
#define read(sock,buf,len) recv(sock,buf,len,0)
#define EWOULDBLOCK WSAEWOULDBLOCK
#define ETIMEDOUT WSAETIMEDOUT
#define write(sock,buf,len) send(sock,buf,len,0)
#endif
*/
int rfbMaxClientWait = 20000; /* time (ms) after which we decide client has
gone away - needed to stop us hanging */
......@@ -334,7 +329,9 @@ rfbCloseClient(cl)
while(cl->screen->maxFd>0
&& !FD_ISSET(cl->screen->maxFd,&(cl->screen->allFds)))
cl->screen->maxFd--;
#ifndef __MINGW32__
shutdown(cl->sock,SHUT_RDWR);
#endif
close(cl->sock);
cl->sock = -1;
}
......
......@@ -41,6 +41,10 @@ extern "C"
#include <sys/types.h>
#endif
#ifdef __MINGW32__
#include <winsock2.h>
#endif
#ifdef LIBVNCSERVER_HAVE_LIBPTHREAD
#include <pthread.h>
#if 0 /* debugging */
......@@ -208,7 +212,7 @@ typedef struct _rfbScreenInfo
SOCKET listenSock;
int maxSock;
int maxFd;
fd_set allFds;
struct fd_set allFds;
rfbBool socketInitDone;
SOCKET inetdSock;
......
......@@ -47,7 +47,7 @@
*/
#if defined(WIN32)
#if defined(WIN32) && !defined(__MINGW32__)
#define LIBVNCSERVER_WORDS_BIGENDIAN
#define rfbBool int
#include <sys/timeb.h>
......@@ -65,7 +65,7 @@
#endif
#if !defined(WIN32)
#if !defined(WIN32) || defined(__MINGW32__)
#define max(a,b) (((a)>(b))?(a):(b))
#ifdef LIBVNCSERVER_HAVE_SYS_TIME_H
#include <sys/time.h>
......
DEFINES=-I.. -g -Wall
LDADD = ../libvncserver/libvncserver.a ../libvncclient/libvncclient.a @WSOCKLIB@
if HAVE_LIBPTHREAD
BACKGROUND_TEST=blooptest
ENCODINGS_TEST=encodingstest
endif
copyrecttest_LDADD=$(LDADD) -lm
noinst_PROGRAMS=encodingstest cargstest copyrecttest $(BACKGROUND_TEST)
LDADD = ../libvncserver/libvncserver.a ../libvncclient/libvncclient.a
noinst_PROGRAMS=$(ENCODINGS_TEST) cargstest copyrecttest $(BACKGROUND_TEST)
test: encodingstest cargstest copyrecttest
./encodingstest && ./cargstest
......
......@@ -4,7 +4,7 @@ noinst_HEADERS=VNConsole.h vga.h
CFLAGS_ADD=-I..
LDADD=../libvncserver/libvncserver.a
LDADD=../libvncserver/libvncserver.a @WSOCKLIB@
INCLUDES=-I.
if LINUX
......@@ -12,7 +12,13 @@ bin_PROGRAMS=LinuxVNC
LinuxVNC_SOURCES=LinuxVNC.c $(CONSOLE_SRCS)
endif
noinst_PROGRAMS=VNCommand example
VNCommand_SOURCES=VNCommand.c $(CONSOLE_SRCS)
if ! MINGW
VNCOMMAND=VNCommand
endif
noinst_PROGRAMS=example $(VNCOMMAND)
example_SOURCES=example.c $(CONSOLE_SRCS)
VNCommand_SOURCES=VNCommand.c $(CONSOLE_SRCS)
DEFINES = -I ..
LDADD = ../libvncserver/libvncserver.a
LDADD = ../libvncserver/libvncserver.a @WSOCKLIB@
man_MANS=x11vnc.1
EXTRA_DIST=ChangeLog README $(man_MANS)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment