Changeset 1800 for Whitix/trunk/net
- Timestamp:
- 01/20/09 23:27:54 (3 years ago)
- Location:
- Whitix/trunk/net
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
Whitix/trunk/net/local.c
r1784 r1800 108 108 struct LocalSocketAddr* socketAddr=(struct LocalSocketAddr*)addr; 109 109 struct LocalSocketAddr* serverSockAddr; 110 struct LocalSockInfo* serverInfo ;111 struct Socket* curr, * serverSock=NULL;110 struct LocalSockInfo* serverInfo, *clientInfo; 111 struct Socket* curr, *curr2, *serverSock=NULL; 112 112 113 113 /* Can only connect to local sockets. */ … … 116 116 117 117 /* Find server socket. */ 118 ListForEachEntry (curr, &localListenSockets, next)118 ListForEachEntrySafe(curr, curr2, &localListenSockets, next) 119 119 { 120 120 serverSockAddr=(struct LocalSocketAddr*)&curr->addr; … … 129 129 return -ENOENT; 130 130 131 clientInfo = (struct LocalSockInfo*)(socket->protoInfo); 132 131 133 serverInfo=(struct LocalSockInfo*)(serverSock->protoInfo); 132 134 socket->state=SOCKET_STATE_WAITING; … … 140 142 WakeUp(&serverInfo->waitQueue); 141 143 142 while (socket->state != SOCKET_STATE_CONNECTED) /* FIXME: or socket state is error. */ 143 ThrSchedule(); 144 WAIT_ON(&clientInfo->waitQueue, socket->state == SOCKET_STATE_CONNECTED); 144 145 145 146 return 0; … … 200 201 struct Socket* client, *child; 201 202 struct LocalSockInfo* info=(struct LocalSockInfo*)(socket->protoInfo); 203 struct LocalSockInfo* clientInfo; 202 204 int ret; 203 205 … … 213 215 if (ret < 0) 214 216 return ret; 215 217 216 218 if (addr) 217 219 { … … 229 231 LocalSetPeer(child, client); 230 232 LocalSetPeer(client, child); 233 234 clientInfo = (struct LocalSockInfo*)(client->protoInfo); 235 WakeUp(&clientInfo->waitQueue); 231 236 232 237 return ret; … … 302 307 PreemptEnable(); 303 308 } 309 310 return pos-orig; 311 } 312 313 int LocalPoll(struct Socket* socket, struct PollItem* item, struct PollQueue* pollQueue) 314 { 315 struct LocalSockInfo* info=(struct LocalSockInfo*)(socket->protoInfo); 316 317 PollAddWait(pollQueue, &info->waitQueue); 318 319 if ((socket->type & SOCKET_TYPE_SERVER) && !ListEmpty(&info->waitingSocks)) 320 item->revents |= POLL_IN; 304 321 305 return pos-orig; 306 } 307 308 int LocalPoll(struct Socket* socket, struct PollItem* item, struct PollQueue* pollQueue) 309 { 310 struct LocalSockInfo* info=(struct LocalSockInfo*)(socket->protoInfo); 311 312 if (((socket->type & SOCKET_TYPE_SERVER && !ListEmpty(&info->waitingSocks)) || 313 (!(socket->type & SOCKET_TYPE_SERVER) && !ListEmpty(&socket->recvPackets)))) 314 { 315 item->revents|=POLL_IN; 316 } 322 if ((!(socket->type & SOCKET_TYPE_SERVER) && !ListEmpty(&socket->recvPackets))) 323 item->revents |= POLL_IN; 317 324 318 325 item->revents |= POLL_OUT; 319 326 320 PollAddWait(pollQueue, &info->waitQueue); 327 if (!(socket->type & SOCKET_TYPE_SERVER) && !info->peer) 328 item->revents |= POLL_ERR; 321 329 322 330 return 0; -
Whitix/trunk/net/socket.c
r1784 r1800 101 101 struct File* file; 102 102 103 file =FileGet(fd);104 103 file = FileGet(fd); 104 105 105 if (!file) 106 106 return NULL; … … 126 126 struct File* file; 127 127 128 file =FileGet(socket->fd);128 file = FileGet(socket->fd); 129 129 130 130 if (UNLIKELY(!file)) 131 131 return; 132 133 /* When the VFS allocates a file descriptor to a process, it looks134 * for a NULL vNode pointer in the file structure to indicate a 'free'135 * file structure. */136 file->vNode=NULL;137 132 } 138 133 … … 228 223 return newFd; 229 224 230 newSocket=SOCKET_GET(current->files[newFd] .vNode);225 newSocket=SOCKET_GET(current->files[newFd]->vNode); 231 226 SocketSetupChild(server, newSocket); 232 227 *child=newSocket; … … 306 301 int SocketCreateFile(struct File* file, struct Socket* socket) 307 302 { 308 file->vNode =VNodeGetEmpty();309 file->fileOps =file->vNode->fileOps=&sockFileOps;310 file->vNode->extraInfo =(void*)socket;311 file->vNode->superBlock =&socketSuperBlock;303 file->vNode = VNodeGetEmpty(); 304 file->fileOps = file->vNode->fileOps=&sockFileOps; 305 file->vNode->extraInfo = (void*)socket; 306 file->vNode->superBlock = &socketSuperBlock; 312 307 313 308 return 0; … … 329 324 return -ENOMEM; 330 325 331 sockFd =VfsGetFreeFd(current);326 sockFd = VfsGetFreeFd(current); 332 327 333 328 if (sockFd < 0) 334 329 return sockFd; 335 336 SocketCreateFile(¤t->files[sockFd], socket); 330 331 current->files[sockFd] = FileAllocate(); 332 333 SocketCreateFile(current->files[sockFd], socket); 337 334 338 335 return sockFd; … … 367 364 struct Socket* socket; 368 365 369 socket =SocketGet(fd);366 socket = SocketGet(fd); 370 367 371 368 if (!socket)
