@@ -517,7 +517,7 @@ WSPSetSockOpt(IN SOCKET Handle,
517
517
PSOCKET_INFORMATION Socket ;
518
518
INT ErrorCode ;
519
519
PWINSOCK_TEB_DATA ThreadData ;
520
-
520
+
521
521
/* Enter prolog */
522
522
ErrorCode = SockEnterApiFast (& ThreadData );
523
523
if (ErrorCode != NO_ERROR )
@@ -526,7 +526,7 @@ WSPSetSockOpt(IN SOCKET Handle,
526
526
* lpErrno = ErrorCode ;
527
527
return SOCKET_ERROR ;
528
528
}
529
-
529
+
530
530
/* Get the socket structure */
531
531
Socket = SockFindAndReferenceSocket (Handle , TRUE);
532
532
if (!Socket )
@@ -535,55 +535,170 @@ WSPSetSockOpt(IN SOCKET Handle,
535
535
* lpErrno = WSAENOTSOCK ;
536
536
return SOCKET_ERROR ;
537
537
}
538
-
538
+
539
539
/* Lock the socket */
540
540
EnterCriticalSection (& Socket -> Lock );
541
-
541
+
542
542
/* Make sure we're not closed */
543
543
if (Socket -> SharedData .State == SocketClosed )
544
544
{
545
545
/* Fail */
546
546
ErrorCode = WSAENOTSOCK ;
547
547
goto error ;
548
548
}
549
-
549
+
550
550
/* Validate the pointer */
551
551
if (!OptionValue )
552
552
{
553
553
/* Fail */
554
554
ErrorCode = WSAEFAULT ;
555
555
goto error ;
556
556
}
557
-
557
+
558
558
/* Validate option */
559
559
if (!IsValidOptionForSocket (Socket , Level , OptionName ))
560
560
{
561
561
/* Fail */
562
562
ErrorCode = WSAENOPROTOOPT ;
563
563
goto error ;
564
564
}
565
-
566
- /* FIXME: Write code */
567
-
565
+
566
+ /* Check the Level first */
567
+ switch (Level )
568
+ {
569
+ /* Handle SOL_SOCKET */
570
+ case SOL_SOCKET :
571
+
572
+ /* Now check the Option */
573
+ switch (OptionName )
574
+ {
575
+ case SO_RCVBUF :
576
+
577
+ /* Validate the size */
578
+ if (OptionLength < sizeof (INT ))
579
+ {
580
+ /* Size is too small, fail */
581
+ ErrorCode = WSAEFAULT ;
582
+ goto error ;
583
+ }
584
+
585
+ /* Set the data */
586
+ Socket -> SharedData .SizeOfRecvBuffer = * (PINT )OptionValue ;
587
+
588
+ /* FIXME: Tell AFD */
589
+ break ;
590
+
591
+ case SO_SNDBUF :
592
+
593
+ /* Validate the size */
594
+ if (OptionLength < sizeof (INT ))
595
+ {
596
+ /* Size is too small, fail */
597
+ ErrorCode = WSAEFAULT ;
598
+ goto error ;
599
+ }
600
+
601
+ /* Set the data */
602
+ Socket -> SharedData .SizeOfSendBuffer = * (PINT )OptionValue ;
603
+
604
+ /* FIXME: Tell AFD */
605
+ break ;
606
+
607
+ case SO_BROADCAST :
608
+
609
+ /* Validate the size */
610
+ if (OptionLength < sizeof (INT ))
611
+ {
612
+ /* Size is too small, fail */
613
+ ErrorCode = WSAEFAULT ;
614
+ goto error ;
615
+ }
616
+
617
+ /* Set the data */
618
+ Socket -> SharedData .Broadcast = * (PINT )OptionValue ;
619
+ break ;
620
+
621
+ case SO_DEBUG :
622
+
623
+ /* Validate the size */
624
+ if (OptionLength < sizeof (INT ))
625
+ {
626
+ /* Size is too small, fail */
627
+ ErrorCode = WSAEFAULT ;
628
+ goto error ;
629
+ }
630
+
631
+ /* Set the data */
632
+ Socket -> SharedData .Debug = * (PINT )OptionValue ;
633
+ break ;
634
+
635
+ case SO_CONDITIONAL_ACCEPT :
636
+ case SO_DONTLINGER :
637
+ case SO_DONTROUTE :
638
+ case SO_ERROR :
639
+ case SO_GROUP_PRIORITY :
640
+ case SO_KEEPALIVE :
641
+ case SO_LINGER :
642
+ case SO_OOBINLINE :
643
+ case SO_REUSEADDR :
644
+
645
+ /* Unsupported */
646
+
647
+ default :
648
+
649
+ /* Unsupported by us, give it to the helper */
650
+ ErrorCode = SockGetTdiHandles (Socket );
651
+ if (ErrorCode != NO_ERROR ) goto error ;
652
+
653
+ /* Call the helper */
654
+ ErrorCode = Socket -> HelperData -> WSHSetSocketInformation (Socket -> HelperContext ,
655
+ Handle ,
656
+ Socket -> TdiAddressHandle ,
657
+ Socket -> TdiConnectionHandle ,
658
+ Level ,
659
+ OptionName ,
660
+ (PCHAR )OptionValue ,
661
+ OptionLength );
662
+ if (ErrorCode != NO_ERROR ) goto error ;
663
+ break ;
664
+ }
665
+ break ;
666
+
667
+ default :
668
+
669
+ /* Unsupported by us, give it to the helper */
670
+ ErrorCode = SockGetTdiHandles (Socket );
671
+ if (ErrorCode != NO_ERROR ) goto error ;
672
+
673
+ /* Call the helper */
674
+ ErrorCode = Socket -> HelperData -> WSHSetSocketInformation (Socket -> HelperContext ,
675
+ Handle ,
676
+ Socket -> TdiAddressHandle ,
677
+ Socket -> TdiConnectionHandle ,
678
+ Level ,
679
+ OptionName ,
680
+ (PCHAR )OptionValue ,
681
+ OptionLength );
682
+ if (ErrorCode != NO_ERROR ) goto error ;
683
+ break ;
684
+ }
685
+
568
686
error :
569
-
687
+ /* Dereference and unlock the socket */
688
+ LeaveCriticalSection (& Socket -> Lock );
689
+ SockDereferenceSocket (Socket );
690
+
570
691
/* Check if this is the failure path */
571
692
if (ErrorCode != NO_ERROR )
572
693
{
573
- /* Dereference and unlock the socket */
574
- LeaveCriticalSection (& Socket -> Lock );
575
- SockDereferenceSocket (Socket );
576
-
577
694
/* Return error */
578
695
* lpErrno = ErrorCode ;
579
696
return SOCKET_ERROR ;
580
697
}
581
-
698
+
582
699
/* Update the socket's state in AFD */
583
700
ErrorCode = SockSetHandleContext (Socket );
584
- if (ErrorCode != NO_ERROR ) goto error ;
585
-
701
+
586
702
/* Return success */
587
- return NO_ERROR ;
703
+ return ErrorCode ;
588
704
}
589
-
0 commit comments