OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/udp/udp_socket_win.h" | 5 #include "net/udp/udp_socket_win.h" |
6 | 6 |
7 #include <mstcpip.h> | 7 #include <mstcpip.h> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 CHECK_NE(INVALID_SOCKET, socket_); | 522 CHECK_NE(INVALID_SOCKET, socket_); |
523 AssertEventNotSignaled(core_->read_overlapped_.hEvent); | 523 AssertEventNotSignaled(core_->read_overlapped_.hEvent); |
524 int rv = WSARecvFrom(socket_, &read_buffer, 1, &num, &flags, storage.addr, | 524 int rv = WSARecvFrom(socket_, &read_buffer, 1, &num, &flags, storage.addr, |
525 &storage.addr_len, &core_->read_overlapped_, NULL); | 525 &storage.addr_len, &core_->read_overlapped_, NULL); |
526 if (rv == 0) { | 526 if (rv == 0) { |
527 if (ResetEventIfSignaled(core_->read_overlapped_.hEvent)) { | 527 if (ResetEventIfSignaled(core_->read_overlapped_.hEvent)) { |
528 int result = num; | 528 int result = num; |
529 // Convert address. | 529 // Convert address. |
530 if (address && result >= 0) { | 530 if (address && result >= 0) { |
531 if (!ReceiveAddressToIPEndpoint(address)) | 531 if (!ReceiveAddressToIPEndpoint(address)) |
532 result = ERR_FAILED; | 532 result = ERR_ADDRESS_INVALID; |
533 } | 533 } |
534 LogRead(result, buf->data()); | 534 LogRead(result, buf->data()); |
535 return result; | 535 return result; |
536 } | 536 } |
537 } else { | 537 } else { |
538 int os_error = WSAGetLastError(); | 538 int os_error = WSAGetLastError(); |
539 if (os_error != WSA_IO_PENDING) { | 539 if (os_error != WSA_IO_PENDING) { |
540 int result = MapSystemError(os_error); | 540 int result = MapSystemError(os_error); |
541 LogRead(result, NULL); | 541 LogRead(result, NULL); |
542 return result; | 542 return result; |
543 } | 543 } |
544 } | 544 } |
545 core_->WatchForRead(); | 545 core_->WatchForRead(); |
546 core_->read_iobuffer_ = buf; | 546 core_->read_iobuffer_ = buf; |
547 return ERR_IO_PENDING; | 547 return ERR_IO_PENDING; |
548 } | 548 } |
549 | 549 |
550 int UDPSocketWin::InternalSendTo(IOBuffer* buf, int buf_len, | 550 int UDPSocketWin::InternalSendTo(IOBuffer* buf, int buf_len, |
551 const IPEndPoint* address) { | 551 const IPEndPoint* address) { |
552 DCHECK(!core_->write_iobuffer_); | 552 DCHECK(!core_->write_iobuffer_); |
553 SockaddrStorage storage; | 553 SockaddrStorage storage; |
554 struct sockaddr* addr = storage.addr; | 554 struct sockaddr* addr = storage.addr; |
555 // Convert address. | 555 // Convert address. |
556 if (!address) { | 556 if (!address) { |
557 addr = NULL; | 557 addr = NULL; |
558 storage.addr_len = 0; | 558 storage.addr_len = 0; |
559 } else { | 559 } else { |
560 if (!address->ToSockAddr(addr, &storage.addr_len)) { | 560 if (!address->ToSockAddr(addr, &storage.addr_len)) { |
561 int result = ERR_FAILED; | 561 int result = ERR_ADDRESS_INVALID; |
562 LogWrite(result, NULL, NULL); | 562 LogWrite(result, NULL, NULL); |
563 return result; | 563 return result; |
564 } | 564 } |
565 } | 565 } |
566 | 566 |
567 WSABUF write_buffer; | 567 WSABUF write_buffer; |
568 write_buffer.buf = buf->data(); | 568 write_buffer.buf = buf->data(); |
569 write_buffer.len = buf_len; | 569 write_buffer.len = buf_len; |
570 | 570 |
571 DWORD flags = 0; | 571 DWORD flags = 0; |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 return OK; | 804 return OK; |
805 } | 805 } |
806 | 806 |
807 // TODO(hubbe): Implement differentiated services for windows. | 807 // TODO(hubbe): Implement differentiated services for windows. |
808 // Note: setsockopt(IP_TOS) does not work on windows XP and later. | 808 // Note: setsockopt(IP_TOS) does not work on windows XP and later. |
809 int UDPSocketWin::SetDiffServCodePoint(DiffServCodePoint dscp) { | 809 int UDPSocketWin::SetDiffServCodePoint(DiffServCodePoint dscp) { |
810 return ERR_NOT_IMPLEMENTED; | 810 return ERR_NOT_IMPLEMENTED; |
811 } | 811 } |
812 | 812 |
813 } // namespace net | 813 } // namespace net |
OLD | NEW |