Changeset 7180
- Timestamp:
- 02/27/08 15:05:04 (5 years ago)
- Location:
- lang/c/partty/trunk
- Files:
-
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/c/partty/trunk/host.cc
r7068 r7180 79 79 { 80 80 uint16_t msglen = ntohs(reply.message_length); 81 char* msg = (char*)malloc(msglen );81 char* msg = (char*)malloc(msglen+1); 82 82 if( msg == NULL ) { 83 83 throw initialize_error("failed to receive negotiation reply"); … … 88 88 } 89 89 if( reply.code != negotiation_reply::SUCCESS ) { 90 msg[msglen] = '\0'; 90 91 initialize_error e(msg); 91 92 free(msg); … … 160 161 } else if( len == 0 ) { throw io_end_error("end of stdinput"); } 161 162 // ブロックしながらシェルに書き込む 162 // XXX 書き込み可能になるまでビジーループ 163 if( write_all(sh, shared_buffer, len) != (size_t)len ){ 163 if( continued_blocking_write_all(sh, shared_buffer, len) != (size_t)len ){ 164 164 throw io_error("pty is broken"); 165 165 } … … 191 191 if( m_locking ) { return 0; } 192 192 // ブロックしながらシェルに書き込む 193 // XXX 書き込み可能になるまでビジーループ 194 if( write_all(sh, shared_buffer, len) != (size_t)len ){ 193 if( continued_blocking_write_all(sh, shared_buffer, len) != (size_t)len ){ 195 194 throw io_error("pty is broken"); 196 195 } … … 208 207 } else if( len == 0 ) { throw io_end_error("session ends"); } 209 208 // ブロックしながら標準出力に書き込む 210 // XXX 書き込み可能になるまでビジーループ 211 if( write_all(STDOUT_FILENO, shared_buffer, len) != (size_t)len ) { 209 if( continued_blocking_write_all(STDOUT_FILENO, shared_buffer, len) != (size_t)len ) { 212 210 throw io_error("stdoutput is broken"); 213 211 } 214 212 // ブロックしながらServerに書き込む 215 // XXX 書き込み可能になるまでビジーループ 216 if( write_all(server, shared_buffer, len) != (size_t)len ) { 213 if( continued_blocking_write_all(server, shared_buffer, len) != (size_t)len ) { 217 214 throw io_error("server connection is broken"); 218 215 } -
lang/c/partty/trunk/multiplexer.cc
r7068 r7180 75 75 for(delimiter = 0x3A; delimiter <= 0x7E; ++delimiter) { 76 76 // ':' - '~' 77 if( !(exist = strchr(info.session_name, delimiter)) ) { break; }77 if( (exist = strchr(info.session_name, delimiter)) ) { break; } 78 78 } 79 79 if( !exist ) { 80 80 for(delimiter = 0x21; delimiter < 0x3A; ++delimiter) { 81 81 // '!' - '9' 82 if( !(exist = strchr(info.session_name, delimiter)) ) { break; }82 if( (exist = strchr(info.session_name, delimiter)) ) { break; } 83 83 } 84 84 } … … 195 195 ssize_t len = read(fd, shared_buffer, SHARED_BUFFER_SIZE); 196 196 if( len < 0 ) { 197 if( errno == EAGAIN || errno == EINTR ) { /* do nothing */}197 if( errno == EAGAIN || errno == EINTR ) { return 0; } 198 198 else { throw io_error("host socket is broken"); } 199 199 } else if( len == 0 ) { … … 226 226 ssize_t len = read(fd, shared_buffer, SHARED_BUFFER_SIZE); 227 227 if( len < 0 ) { 228 if( errno == EAGAIN || errno == EINTR ) { /* do nothing*/ }228 if( errno == EAGAIN || errno == EINTR ) { /* pass through */ } 229 229 else { 230 230 perror("read from guest failed"); … … 243 243 return 0; 244 244 } 245 // FIXME write_all? ブロッキングモードにする?246 245 // FIXME Hostが切断されたのかエラーが発生したのか区別できない 247 if( write_all(host, ibuf.buf, ibuf.len) != ibuf.len ) {246 if( continued_blocking_write_all(host, ibuf.buf, ibuf.len) != ibuf.len ) { 248 247 throw io_error("host socket is broken"); 249 248 } … … 257 256 //if( srv.olength == 0 ) { return 0; } // olengthは0の可能性がある? 258 257 if( len < 0 ) { 259 if( errno == EAGAIN || errno == EINTR ) { /* do nothing */}258 if( errno == EAGAIN || errno == EINTR ) { return 0; } 260 259 else { 261 260 perror("write to guest failed"); -
lang/c/partty/trunk/partty.h
r7170 r7180 12 12 13 13 #ifndef PARTTY_GATE_DIR 14 #define PARTTY_GATE_DIR "./var/" 15 #endif 16 17 //#ifndef PARTTY_GATE_SOCKET_NAME 18 //#define PARTTY_GATE_SOCKET_NAME "gate" 19 //#endif 14 #define PARTTY_GATE_DIR "./var/socket/" 15 #endif 16 17 #ifndef PARTTY_ARCHIVE_DIR 18 #define PARTTY_ARCHIVE_DIR \ 19 "./archive/archive/" 20 #endif 20 21 21 22 #ifndef PARTTY_GATE_SESSION_BANNER … … 65 66 66 67 static const char* const GATE_DIR = PARTTY_GATE_DIR; 67 //static const char* const GATE_SOCKET_NAME = PARTTY_GATE_SOCKET_NAME;68 static const char* const ARCHIVE_DIR = PARTTY_ARCHIVE_DIR; 68 69 static const char* const GATE_PASSWORD_BANNER = PARTTY_GATE_PASSWORD_BANNER; 69 70 static const char* const GATE_SESSION_BANNER = PARTTY_GATE_SESSION_BANNER; … … 73 74 74 75 75 //static const char PARTTY_VERSION[] = "0.0";76 //static const char PARTTY_REVISION[] = "0";77 76 static const uint8_t PROTOCOL_VERSION = 1; 78 77 … … 239 238 class Host { 240 239 public: 240 struct config_t { 241 config_t(int _server_socket, 242 const session_info_ref_t& info_) : 243 server_socket(_server_socket), 244 info(info_) {} 245 public: 246 int lock_code; 247 private: 248 int server_socket; 249 const session_info_ref_t& info; 250 friend class HostIMPL; 251 }; 252 public: 241 253 Host(int server_socket, char lock_code, 242 254 const session_info_ref_t& info); … … 255 267 class Gate { 256 268 public: 269 struct config_t { 270 config_t(int listen_socket_) : 271 listen_socket(listen_socket_) {} 272 public: 273 private: 274 int listen_socket; 275 friend class GateIMPL; 276 }; 277 public: 257 278 Gate(int listen_socket); 258 279 ~Gate(); -
lang/c/partty/trunk/uniext.h
r7068 r7180 5 5 #include <unistd.h> 6 6 #include <errno.h> 7 #include <fcntl.h> 7 8 8 9 namespace Partty { 9 10 10 11 11 inline size_t read_all(int fd, void *buf, size_t count) { 12 inline size_t read_all(int fd, void *buf, size_t count) 13 { 12 14 char *p = (char*)buf; 13 15 char * const endp = p + count; 14 16 15 17 do { 16 const int num_bytes = read(fd, p, endp - p);18 const ssize_t num_bytes = read(fd, p, endp - p); 17 19 if( num_bytes < 0 ) { 18 20 if( errno != EINTR && errno != EAGAIN ) { … … 27 29 } 28 30 29 inline size_t write_all(int fd, const void *buf, size_t count) { 31 inline size_t write_all(int fd, const void *buf, size_t count) 32 { 30 33 const char *p = (char*)buf; 31 34 const char * const endp = p + count; 32 35 33 36 do { 34 const int num_bytes = write(fd, p, endp - p);37 const ssize_t num_bytes = write(fd, p, endp - p); 35 38 if( num_bytes < 0 ) { 36 39 if( errno != EINTR && errno != EAGAIN ) { … … 45 48 } 46 49 50 inline size_t continued_blocking_read_all(int fd, void* buf, size_t count) 51 { 52 ssize_t num_bytes; 53 54 num_bytes = read(fd, buf, count); 55 if( num_bytes >= count ) { 56 return num_bytes; 57 } else if( num_bytes <= 0 ) { 58 if( errno != EINTR && errno != EAGAIN ) { return 0; } 59 else { num_bytes = 0; } 60 } 61 62 fcntl(fd, F_SETFL, 0); 63 64 char *p = (char*)buf + num_bytes; 65 char * const endp = (char*)buf + count; 66 67 do { 68 num_bytes = read(fd, p, endp - p); 69 if( num_bytes < 0 ) { 70 if( errno != EINTR && errno != EAGAIN ) { 71 break; 72 } 73 } else { 74 p += num_bytes; 75 } 76 } while (p < endp); 77 78 fcntl(fd, F_SETFL, O_NONBLOCK); 79 80 return endp - p; 81 } 82 83 inline size_t continued_blocking_write_all(int fd, const void* buf, size_t count) 84 { 85 ssize_t num_bytes; 86 87 num_bytes = write(fd, buf, count); 88 if( num_bytes >= count ) { 89 return num_bytes; 90 } else if( num_bytes <= 0 ) { 91 if( errno != EINTR && errno != EAGAIN ) { return 0; } 92 else { num_bytes = 0; } 93 } 94 95 fcntl(fd, F_SETFL, 0); 96 97 const char *p = (char*)buf + num_bytes; 98 const char * const endp = (char*)buf + count; 99 100 do { 101 num_bytes = write(fd, p, endp - p); 102 if( num_bytes < 0 ) { 103 if( errno != EINTR && errno != EAGAIN ) { 104 break; 105 } 106 } else { 107 p += num_bytes; 108 } 109 } while (p < endp); 110 111 fcntl(fd, F_SETFL, O_NONBLOCK); 112 113 return endp - p; 114 } 115 47 116 void initprocname(int argc, char**& argv, char**& envp); 48 117
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)