/[rdesktop]/sourceforge.net/trunk/seamlessrdp/ServerExe/vchannel.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sourceforge.net/trunk/seamlessrdp/ServerExe/vchannel.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1073 by ossman_, Thu Mar 9 12:26:31 2006 UTC revision 1074 by ossman_, Thu Mar 9 13:24:35 2006 UTC
# Line 22  Line 22 
22  #include <assert.h>  #include <assert.h>
23  #include <stdio.h>  #include <stdio.h>
24  #include <stdarg.h>  #include <stdarg.h>
25    #include <errno.h>
26    
27  #include <windows.h>  #include <windows.h>
28  #include <wtsapi32.h>  #include <wtsapi32.h>
# Line 92  vchannel_is_open() Line 93  vchannel_is_open()
93  }  }
94    
95  int  int
96  vchannel_read(char *buffer, size_t length)  vchannel_read(char *line, size_t length)
97  {  {
98          return -1;          static BOOL overflow_mode = FALSE;
99            static char buffer[VCHANNEL_MAX_LINE];
100            static size_t size = 0;
101    
102            char *newline;
103            int line_size;
104    
105            BOOL result;
106            ULONG bytes_read;
107    
108            result = WTSVirtualChannelRead(g_vchannel, 0, buffer + size,
109                                           sizeof(buffer) - size, &bytes_read);
110    
111            if (!result) {
112                    errno = EIO;
113                    return -1;
114            }
115    
116            if (overflow_mode) {
117                    newline = strchr(buffer, '\n');
118                    if (newline && (newline - buffer) < bytes_read) {
119                            size = bytes_read - (newline - buffer) - 1;
120                            memmove(buffer, newline + 1, size);
121                            overflow_mode = FALSE;
122                    }
123            }
124            else
125                    size += bytes_read;
126    
127            if (overflow_mode) {
128                    errno = -EAGAIN;
129                    return -1;
130            }
131    
132            newline = strchr(buffer, '\n');
133            if (!newline || (newline - buffer) >= size) {
134                    if (size == sizeof(buffer)) {
135                            overflow_mode = TRUE;
136                            size = 0;
137                    }
138                    errno = -EAGAIN;
139                    return -1;
140            }
141    
142            if ((newline - buffer) >= length) {
143                    errno = ENOMEM;
144                    return -1;
145            }
146    
147            *newline = '\0';
148    
149            strcpy(line, buffer);
150            line_size = newline - buffer;
151    
152            size -= newline - buffer + 1;
153            memmove(buffer, newline + 1, size);
154    
155            return 0;
156  }  }
157    
158  int  int
# Line 102  vchannel_write(char *format, ...) Line 160  vchannel_write(char *format, ...)
160  {  {
161          BOOL result;          BOOL result;
162          va_list argp;          va_list argp;
163          char buf[1024];          char buf[VCHANNEL_MAX_LINE];
164          int size;          int size;
165          ULONG bytes_written;          ULONG bytes_written;
166    

Legend:
Removed from v.1073  
changed lines
  Added in v.1074

  ViewVC Help
Powered by ViewVC 1.1.26