Fix problems with ascii log files, also problems with WSAEWOULDBLOCK on send buffer/receive window full.

This commit is contained in:
Ron Pedde 2007-08-06 05:18:01 +00:00
parent 5cf869342b
commit 366ae9913c
6 changed files with 52 additions and 27 deletions

View File

@ -360,7 +360,7 @@ int err_setlogfile(char *file) {
strncpy(err_filename,file,sizeof(err_filename)-1); strncpy(err_filename,file,sizeof(err_filename)-1);
if(!io_open(err_file,"file://%U?mode=%s",err_filename,mode)) { if(!io_open(err_file,"file://%U?mode=%s&ascii=1",err_filename,mode)) {
fprintf(stderr,"Error opening logfile: %s",io_errstr(err_file)); fprintf(stderr,"Error opening logfile: %s",io_errstr(err_file));
err_logdest &= ~LOGDEST_LOGFILE; err_logdest &= ~LOGDEST_LOGFILE;

View File

@ -23,7 +23,7 @@
#define _IO_ERRORS_H_ #define _IO_ERRORS_H_
#define IO_E_OTHER 0x00000001 /**< Native error */ #define IO_E_OTHER 0x00000000 /**< Native error */
#define IO_E_BADPROTO 0x01000001 /**< Bad protocol type, unhandled URI */ #define IO_E_BADPROTO 0x01000001 /**< Bad protocol type, unhandled URI */
#define IO_E_NOTINIT 0x01000002 /**< io object not initialized with new */ #define IO_E_NOTINIT 0x01000002 /**< io object not initialized with new */
#define IO_E_BADFN 0x01000003 /**< uniplemented io function */ #define IO_E_BADFN 0x01000003 /**< uniplemented io function */

View File

@ -1010,9 +1010,9 @@ int io_write(IO_PRIVHANDLE *phandle, unsigned char *buf, uint32_t *len) {
must_free = TRUE; must_free = TRUE;
dst = real_buffer; dst = real_buffer;
for(index = 0; index < *len; index++) { for(index = 0; index < *len; index++) {
*dst++ = buf[index];
if(buf[index] == '\n') if(buf[index] == '\n')
*dst++ = '\r'; *dst++ = '\r';
*dst++ = buf[index];
} }
real_len = ascii_len; real_len = ascii_len;
} else { } else {
@ -1294,6 +1294,10 @@ void io_err(IO_PRIVHANDLE *phandle, uint32_t errorcode) {
/* underlying provider must provide a free-able error message */ /* underlying provider must provide a free-able error message */
phandle->err_str = phandle->fnptr->fn_geterrmsg(phandle, &phandle->err, &phandle->is_local); phandle->err_str = phandle->fnptr->fn_geterrmsg(phandle, &phandle->err, &phandle->is_local);
} }
while((phandle->err_str[strlen(phandle->err_str) - 1] == '\n') ||
(phandle->err_str[strlen(phandle->err_str) -1] == '\r'))
phandle->err_str[strlen(phandle->err_str) -1] = '\0';
} }
/** /**
@ -1389,7 +1393,7 @@ int io_file_open(IO_PRIVHANDLE *phandle, char *uri) {
else else
native_mode |= OPEN_EXISTING; native_mode |= OPEN_EXISTING;
priv->fd = CreateFile(uri,native_permissions,0,NULL, priv->fd = CreateFile(uri,native_permissions,FILE_SHARE_READ,NULL,
native_mode,FILE_ATTRIBUTE_NORMAL,NULL); native_mode,FILE_ATTRIBUTE_NORMAL,NULL);
if(priv->fd == INVALID_HANDLE_VALUE) { if(priv->fd == INVALID_HANDLE_VALUE) {
io_file_seterr(phandle,IO_E_FILE_OTHER); io_file_seterr(phandle,IO_E_FILE_OTHER);
@ -1787,7 +1791,7 @@ char *io_file_geterrmsg(IO_PRIVHANDLE *phandle, ERR_T *code, int *is_local) {
*is_local=FALSE; *is_local=FALSE;
#ifdef WIN32 #ifdef WIN32
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,GetLastError(),MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), NULL,priv->err,MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),
(LPTSTR)lpErrorBuf,sizeof(lpErrorBuf),NULL); (LPTSTR)lpErrorBuf,sizeof(lpErrorBuf),NULL);
return strdup(lpErrorBuf); return strdup(lpErrorBuf);
#else #else
@ -2286,11 +2290,18 @@ int io_socket_write(IO_PRIVHANDLE *phandle, unsigned char *buf,uint32_t *len) {
bufp += byteswritten, bytestowrite -= byteswritten) { bufp += byteswritten, bytestowrite -= byteswritten) {
if(priv->is_udp) { /* must be sending to */ if(priv->is_udp) { /* must be sending to */
slen = sizeof(struct sockaddr_in); slen = sizeof(struct sockaddr_in);
byteswritten = sendto(priv->fd, buf, *len, 0, byteswritten = sendto(priv->fd, bufp, bytestowrite, 0,
(struct sockaddr *)&priv->si_remote, slen); (struct sockaddr *)&priv->si_remote, slen);
} else { } else {
byteswritten = send(priv->fd, buf, *len, 0); byteswritten = send(priv->fd, bufp, bytestowrite, 0);
} }
#ifdef WIN32
if(WSAGetLastError() == WSAEWOULDBLOCK) {
byteswritten = 0;
Sleep(50);
}
#endif
if((byteswritten == -1 ) && (errno != EINTR)) { if((byteswritten == -1 ) && (errno != EINTR)) {
io_socket_seterr(phandle,IO_E_SOCKET_OTHER); io_socket_seterr(phandle,IO_E_SOCKET_OTHER);
return FALSE; return FALSE;
@ -2362,17 +2373,20 @@ void io_socket_seterr(IO_PRIVHANDLE *phandle, ERR_T errcode) {
} else { } else {
priv->local_err = FALSE; priv->local_err = FALSE;
#ifdef WIN32 #ifdef WIN32
/* FIXME: should this be WSAGetLastError? */ priv->err = WSAGetLastError();
priv->err = GetLastError(); /* map error codes to exported errors */
/* FIXME: remap win32 error codes to unix error codes */ if(priv->err == WSAEADDRINUSE) {
priv->err = IO_E_SOCKET_INUSE;
priv->local_err = TRUE;
}
#else #else
priv->err = errno; priv->err = errno;
#endif
/* map error codes to exported errors */ /* map error codes to exported errors */
if(priv->err == EADDRINUSE) { if(priv->err == EADDRINUSE) {
priv->err = IO_E_SOCKET_INUSE; priv->err = IO_E_SOCKET_INUSE;
priv->local_err = TRUE; priv->local_err = TRUE;
} }
#endif
} }
} }
@ -2404,7 +2418,7 @@ char *io_socket_geterrmsg(IO_PRIVHANDLE *phandle, ERR_T *code, int *is_local) {
*is_local = FALSE; *is_local = FALSE;
#ifdef WIN32 #ifdef WIN32
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,priv->local_err,MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), NULL,priv->err,MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),
(LPTSTR)lpErrorBuf,sizeof(lpErrorBuf),NULL); (LPTSTR)lpErrorBuf,sizeof(lpErrorBuf),NULL);
return strdup(lpErrorBuf); return strdup(lpErrorBuf);
@ -2456,7 +2470,7 @@ int io_socket_getwaitable(IO_PRIVHANDLE *phandle, int mode, WAITABLE_T *retval)
} }
#ifdef WIN32 #ifdef WIN32
io_err_printf(IO_LOG_DEBUG,"Building synthesized event for socket\n"); io_err_printf(IO_LOG_SPAM,"Building synthesized event for socket\n");
if(priv->hEvent) { if(priv->hEvent) {
if(mode == priv->wait_mode) { if(mode == priv->wait_mode) {
*retval = priv->hEvent; *retval = priv->hEvent;
@ -2813,7 +2827,7 @@ int io_wait_add(IO_WAITHANDLE *pwait, IO_PRIVHANDLE *phandle, int type) {
return FALSE; return FALSE;
} }
io_err_printf(IO_LOG_DEBUG,"Getting io waitable of type %d\n",type); io_err_printf(IO_LOG_SPAM,"Getting io waitable of type %d\n",type);
if(!phandle->fnptr->fn_getwaitable(phandle, type, &waitable)) { if(!phandle->fnptr->fn_getwaitable(phandle, type, &waitable)) {
io_err_printf(IO_LOG_WARN,"io_wait_add: error getting waitable\n"); io_err_printf(IO_LOG_WARN,"io_wait_add: error getting waitable\n");
return FALSE; return FALSE;
@ -2839,7 +2853,7 @@ int io_wait_add(IO_WAITHANDLE *pwait, IO_PRIVHANDLE *phandle, int type) {
pwait->hWaitItems[pwait->dwItemCount] = waitable; pwait->hWaitItems[pwait->dwItemCount] = waitable;
pwait->ppHandle[pwait->dwItemCount] = phandle; pwait->ppHandle[pwait->dwItemCount] = phandle;
io_err_printf(IO_LOG_DEBUG,"Added event %08X with pHandle %08X as %d\n", io_err_printf(IO_LOG_SPAM,"Added event %08X with pHandle %08X as %d\n",
waitable,phandle,pwait->dwItemCount); waitable,phandle,pwait->dwItemCount);
pwait->dwItemCount++; pwait->dwItemCount++;
@ -2847,7 +2861,7 @@ int io_wait_add(IO_WAITHANDLE *pwait, IO_PRIVHANDLE *phandle, int type) {
if(waitable > pwait->max_fd) if(waitable > pwait->max_fd)
pwait->max_fd = waitable; pwait->max_fd = waitable;
io_err_printf(IO_LOG_INFO,"Adding %d to waitlist\n",waitable); io_err_printf(IO_LOG_SPAM,"Adding %d to waitlist\n",waitable);
if(type & IO_WAIT_READ) if(type & IO_WAIT_READ)
FD_SET(waitable,&pwait->read_fds); FD_SET(waitable,&pwait->read_fds);
@ -2893,7 +2907,7 @@ int io_wait(IO_WAITHANDLE *pwait, uint32_t *ms) {
#ifdef WIN32 #ifdef WIN32
ASSERT(pwait->dwItemCount); ASSERT(pwait->dwItemCount);
io_err_printf(IO_LOG_INFO,"Waiting on %d items for %d sec\n", io_err_printf(IO_LOG_SPAM,"Waiting on %d items for %d sec\n",
pwait->dwItemCount,timeout.tv_sec); pwait->dwItemCount,timeout.tv_sec);
while(1) { while(1) {
@ -2911,7 +2925,7 @@ int io_wait(IO_WAITHANDLE *pwait, uint32_t *ms) {
} }
/* Was definitely a WAIT_OBJECT_x. Make sure it's not spurious */ /* Was definitely a WAIT_OBJECT_x. Make sure it's not spurious */
io_err_printf(IO_LOG_DEBUG,"Got wait on index %d\n",pwait->dwWhichEvent); io_err_printf(IO_LOG_SPAM,"Got wait on index %d\n",pwait->dwWhichEvent);
if(!pwait->ppHandle[pwait->dwWhichEvent]->fnptr->fn_getsocket) { /* not a socket, must be a file */ if(!pwait->ppHandle[pwait->dwWhichEvent]->fnptr->fn_getsocket) { /* not a socket, must be a file */
/* dummy up a result */ /* dummy up a result */
pwait->wsaNetworkEvents.lNetworkEvents = FD_READ; pwait->wsaNetworkEvents.lNetworkEvents = FD_READ;
@ -2919,18 +2933,18 @@ int io_wait(IO_WAITHANDLE *pwait, uint32_t *ms) {
} }
if(!pwait->ppHandle[pwait->dwWhichEvent]->fnptr->fn_getsocket(pwait->ppHandle[pwait->dwWhichEvent],&sock)) { if(!pwait->ppHandle[pwait->dwWhichEvent]->fnptr->fn_getsocket(pwait->ppHandle[pwait->dwWhichEvent],&sock)) {
io_err_printf(IO_LOG_WARN,"Could not get socket handle\n"); io_err_printf(IO_LOG_SPAM,"Could not get socket handle\n");
return FALSE; return FALSE;
} }
io_err_printf(IO_LOG_DEBUG,"Getting event details for wait object\n"); io_err_printf(IO_LOG_SPAM,"Getting event details for wait object\n");
WSAEnumNetworkEvents(sock,pwait->hWaitItems[pwait->dwWhichEvent],&pwait->wsaNetworkEvents); WSAEnumNetworkEvents(sock,pwait->hWaitItems[pwait->dwWhichEvent],&pwait->wsaNetworkEvents);
if(pwait->wsaNetworkEvents.lNetworkEvents != 0) { if(pwait->wsaNetworkEvents.lNetworkEvents != 0) {
io_err_printf(IO_LOG_DEBUG,"Got %ld\n",pwait->wsaNetworkEvents.lNetworkEvents); io_err_printf(IO_LOG_SPAM,"Got %ld\n",pwait->wsaNetworkEvents.lNetworkEvents);
break; break;
} }
io_err_printf(IO_LOG_DEBUG,"Skipping spurious wakeup\n"); io_err_printf(IO_LOG_SPAM,"Skipping spurious wakeup\n");
} }
if(pwait->dwLastResult == WAIT_FAILED) if(pwait->dwLastResult == WAIT_FAILED)
@ -2953,7 +2967,7 @@ int io_wait(IO_WAITHANDLE *pwait, uint32_t *ms) {
return FALSE; return FALSE;
} }
io_err_printf(IO_LOG_INFO,"selecting on %d nfds, for %d.%d sec\n", io_err_printf(IO_LOG_SPAM,"selecting on %d nfds, for %d.%d sec\n",
pwait->max_fd+1,timeout.tv_sec,timeout.tv_usec); pwait->max_fd+1,timeout.tv_sec,timeout.tv_usec);
while(((retval = select(pwait->max_fd+1,&pwait->result_read, while(((retval = select(pwait->max_fd+1,&pwait->result_read,

View File

@ -407,10 +407,16 @@ void *os_loadlib(char **pe, char *path) {
void *os_libfunc(char **pe, void *handle, char *function) { void *os_libfunc(char **pe, void *handle, char *function) {
void *retval; void *retval;
char *e;
retval = GetProcAddress((HMODULE)handle, function); retval = GetProcAddress((HMODULE)handle, function);
if(!retval) { if(!retval) {
if(pe) *pe = strdup(os_strerror(0)); if(pe) {
*pe = strdup(os_strerror(0));
e = *pe;
while((e[strlen(e) - 1] == '\n') || (e[strlen(e)-1] == '\r'))
e[strlen(e)-1] = '\0';
}
} }
return retval; return retval;
} }

View File

@ -2015,7 +2015,8 @@ int ws_copyfile(WS_CONNINFO *pwsc, IOHANDLE hfile, uint64_t *bytes_copied) {
bytes_written = bytes_read; bytes_written = bytes_read;
if(!io_write(pwsc->hclient,buf,&bytes_written)) { if(!io_write(pwsc->hclient,buf,&bytes_written)) {
ws_dprintf(L_WS_LOG,"Write error: %s\n",io_errstr(pwsc->hclient)); ws_dprintf(L_WS_LOG,"Write error: %s\n",io_errstr(pwsc->hclient));
break; *bytes_copied = total_bytes;
return FALSE;
} }
if(bytes_written != bytes_read) { if(bytes_written != bytes_read) {

View File

@ -42,7 +42,7 @@
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
Optimization="0" Optimization="0"
AdditionalIncludeDirectories="$(InputDir),..\src,.,.." AdditionalIncludeDirectories="$(InputDir),..\src,.,.."
PreprocessorDefinitions="HAVE_CONFIG_H;ZLIB_DLL;_WINDOWS;FLAC;OGGVORBIS" PreprocessorDefinitions="HAVE_CONFIG_H;ZLIB_DLL;_WINDOWS;WIN32;FLAC;OGGVORBIS"
MinimalRebuild="true" MinimalRebuild="true"
BasicRuntimeChecks="3" BasicRuntimeChecks="3"
RuntimeLibrary="1" RuntimeLibrary="1"
@ -124,7 +124,7 @@
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
AdditionalIncludeDirectories="$(InputDir),..\src,.,.." AdditionalIncludeDirectories="$(InputDir),..\src,.,.."
PreprocessorDefinitions="HAVE_CONFIG_H;ZLIB_DLL;_WINDOWS;FLAC;OGGVORBIS" PreprocessorDefinitions="HAVE_CONFIG_H;ZLIB_DLL;_WINDOWS;WIN32;FLAC;OGGVORBIS"
RuntimeLibrary="0" RuntimeLibrary="0"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
WarningLevel="3" WarningLevel="3"
@ -374,6 +374,10 @@
RelativePath="..\src\io-plugin.h" RelativePath="..\src\io-plugin.h"
> >
</File> </File>
<File
RelativePath="..\src\io.h"
>
</File>
<File <File
RelativePath="..\src\ll.h" RelativePath="..\src\ll.h"
> >