~pythonregexp2.7/python/issue2636-11

« back to all changes in this revision

Viewing changes to Modules/socketmodule.c

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-09-21 17:53:26 UTC
  • mfrom: (39025.1.14 Regexp-2.7)
  • Revision ID: darklord@timehorse.com-20080921175326-92vaej2hc3yuecxb
Merged in changes from the core Regexp branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2647
2647
{
2648
2648
        char *buf;
2649
2649
        int len, n = -1, flags = 0, timeout;
 
2650
        Py_buffer pbuf;
2650
2651
 
2651
 
        if (!PyArg_ParseTuple(args, "s#|i:send", &buf, &len, &flags))
 
2652
        if (!PyArg_ParseTuple(args, "s*|i:send", &pbuf, &flags))
2652
2653
                return NULL;
2653
2654
 
2654
 
        if (!IS_SELECTABLE(s))
 
2655
        if (!IS_SELECTABLE(s)) {
 
2656
                PyBuffer_Release(&pbuf);
2655
2657
                return select_error();
 
2658
        }
 
2659
        buf = pbuf.buf;
 
2660
        len = pbuf.len;
2656
2661
 
2657
2662
        Py_BEGIN_ALLOW_THREADS
2658
2663
        timeout = internal_select(s, 1);
2664
2669
#endif
2665
2670
        Py_END_ALLOW_THREADS
2666
2671
 
 
2672
        PyBuffer_Release(&pbuf);
 
2673
 
2667
2674
        if (timeout == 1) {
2668
2675
                PyErr_SetString(socket_timeout, "timed out");
2669
2676
                return NULL;
2688
2695
{
2689
2696
        char *buf;
2690
2697
        int len, n = -1, flags = 0, timeout;
 
2698
        Py_buffer pbuf;
2691
2699
 
2692
 
        if (!PyArg_ParseTuple(args, "s#|i:sendall", &buf, &len, &flags))
 
2700
        if (!PyArg_ParseTuple(args, "s*|i:sendall", &pbuf, &flags))
2693
2701
                return NULL;
 
2702
        buf = pbuf.buf;
 
2703
        len = pbuf.len;
2694
2704
 
2695
 
        if (!IS_SELECTABLE(s))
 
2705
        if (!IS_SELECTABLE(s)) {
 
2706
                PyBuffer_Release(&pbuf);
2696
2707
                return select_error();
 
2708
        }
2697
2709
 
2698
2710
        Py_BEGIN_ALLOW_THREADS
2699
2711
        do {
2712
2724
                len -= n;
2713
2725
        } while (len > 0);
2714
2726
        Py_END_ALLOW_THREADS
 
2727
        PyBuffer_Release(&pbuf);
2715
2728
 
2716
2729
        if (timeout == 1) {
2717
2730
                PyErr_SetString(socket_timeout, "timed out");
2738
2751
static PyObject *
2739
2752
sock_sendto(PySocketSockObject *s, PyObject *args)
2740
2753
{
 
2754
        Py_buffer pbuf;
2741
2755
        PyObject *addro;
2742
2756
        char *buf;
 
2757
        Py_ssize_t len;
2743
2758
        sock_addr_t addrbuf;
2744
 
        int addrlen, len, n = -1, flags, timeout;
 
2759
        int addrlen, n = -1, flags, timeout;
2745
2760
 
2746
2761
        flags = 0;
2747
 
        if (!PyArg_ParseTuple(args, "s#O:sendto", &buf, &len, &addro)) {
 
2762
        if (!PyArg_ParseTuple(args, "s*O:sendto", &pbuf, &addro)) {
2748
2763
                PyErr_Clear();
2749
 
                if (!PyArg_ParseTuple(args, "s#iO:sendto",
2750
 
                                      &buf, &len, &flags, &addro))
 
2764
                if (!PyArg_ParseTuple(args, "s*iO:sendto",
 
2765
                                      &pbuf, &flags, &addro))
2751
2766
                        return NULL;
2752
2767
        }
 
2768
        buf = pbuf.buf;
 
2769
        len = pbuf.len;
2753
2770
 
2754
 
        if (!IS_SELECTABLE(s))
 
2771
        if (!IS_SELECTABLE(s)) {
 
2772
                PyBuffer_Release(&pbuf);
2755
2773
                return select_error();
 
2774
        }
2756
2775
 
2757
 
        if (!getsockaddrarg(s, addro, SAS2SA(&addrbuf), &addrlen))
 
2776
        if (!getsockaddrarg(s, addro, SAS2SA(&addrbuf), &addrlen)) {
 
2777
                PyBuffer_Release(&pbuf);
2758
2778
                return NULL;
 
2779
        }
2759
2780
 
2760
2781
        Py_BEGIN_ALLOW_THREADS
2761
2782
        timeout = internal_select(s, 1);
2763
2784
                n = sendto(s->sock_fd, buf, len, flags, SAS2SA(&addrbuf), addrlen);
2764
2785
        Py_END_ALLOW_THREADS
2765
2786
 
 
2787
        PyBuffer_Release(&pbuf);
2766
2788
        if (timeout == 1) {
2767
2789
                PyErr_SetString(socket_timeout, "timed out");
2768
2790
                return NULL;
2805
2827
Shut down the reading side of the socket (flag == SHUT_RD), the writing side\n\
2806
2828
of the socket (flag == SHUT_WR), or both ends (flag == SHUT_RDWR).");
2807
2829
 
2808
 
#ifdef MS_WINDOWS
 
2830
#if defined(MS_WINDOWS) && defined(SIO_RCVALL)
2809
2831
static PyObject*
2810
2832
sock_ioctl(PySocketSockObject *s, PyObject *arg)
2811
2833
{
2858
2880
                          METH_NOARGS, getsockname_doc},
2859
2881
        {"getsockopt",    (PyCFunction)sock_getsockopt, METH_VARARGS,
2860
2882
                          getsockopt_doc},
2861
 
#ifdef MS_WINDOWS
 
2883
#if defined(MS_WINDOWS) && defined(SIO_RCVALL)
2862
2884
        {"ioctl",         (PyCFunction)sock_ioctl, METH_VARARGS,
2863
2885
                          sock_ioctl_doc},
2864
2886
#endif